Saving Emails to Disk in C#
Sending emails in C# is a simple task. All you need is a MailMessage object with your email and a SmtpClient to send it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
var message = "your message goes here"; // create the email var mailMessage = new MailMessage(); mailMessage.To.Add(toAddress); mailMessage.Subject = "Sending emails is easy"; mailMessage.From = new MailAddress(fromAddress); mailMessage.Body = message; // send it (settings in web.config / app.config) var smtp = new SmtpClient(); smtp.Send(mailMessage); |
The configuration for the SmtpClient is inside the web.config or app.config can look like this example from Sanjay kumar:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<configuration> <system.net> <mailSettings> <network host="smtp.gmail.com" port="587" password="yourpassword" enableSsl="true"/> </smtp> </mailSettings> </system.net> </configuration> |
Whenever your code is executed, your email will be sent …