简体   繁体   English

如何在C#中通过SMTP发送邮件

[英]How to send mails through smtp in c#

如何在C#中通过SMTP发送邮件

System.Net.Mail.MailMessage in conjunction with System.Net.Mail.SmtpClient System.Net.Mail.MailMessage与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. 您使用System.Net.Mail.MailMessage类创建消息。

Then send it using the SmtpClient class to do the actual sending. 然后使用SmtpClient类发送它以进行实际发送。

There are examples in the linked pages. 链接页面中有示例。

Have a look at the System.Net.Mail.SmtpClient reference. 看一下System.Net.Mail.SmtpClient参考。 It should be what you are looking for 它应该是您要寻找的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM