How to send mails through smtp in c#
How to send mails throu开发者_开发技巧gh smtp in c#
System.Net.Mail.MailMessage in conjunction with System.Net.Mail.SmtpClient
MailMessage mail = new MailMessage();
mail.From = new MailAddress("from address");
mail.Subject = "subject";
mail.Body = "body";
mail.IsBodyHtml = IsHtml;
mail.To.Add("targetaddress");
SmtpClient mailClient = new SmtpClient("smtphost");
mailClient.Credentials = new NetworkCredential("username", "password", "domain");
try
{
mailClient.Send(mail);
}
catch (Exception ex)
{
throw ex;
}
finally
{
mailClient = null;
}
You use the System.Net.Mail.MailMessage
class to create the message.
Then send it using the SmtpClient
class to do the actual sending.
There are examples in the linked pages.
Have a look at the System.Net.Mail.SmtpClient reference. It should be what you are looking for
精彩评论