开发者

How to send mails through smtp in c#

开发者 https://www.devze.com 2022-12-25 03:19 出处:网络
How to send mails throu开发者_开发技巧gh smtp in c#System.Net.Mail.MailMessage in conjunction with System.Net.Mail.SmtpClient

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

0

精彩评论

暂无评论...
验证码 换一张
取 消