库使用.NET的隐式SSL发送SMTP电子邮件

时间:2016-03-14 18:49:04

标签: c# .net email ssl

System.Net.Mail不支持隐式SSL,不推荐使用System.Web.Mail。我尝试了doesn't support Unicode,但{{3}}。是否还有其他免费库用于使用.NET的隐式SSL发送SMTP电子邮件?

1 个答案:

答案 0 :(得分:4)

使用带有SSL的System.Net.Mail发送电子邮件就像将EnableSsl标志设置为true并选择正确的端口一样简单:

MailMessage email = new MailMessage()
{
    From = "sender@sender.com",
    Subject = "subject",
    Body = "body"
};
email.To.Add("recipient@recipient.com");
using (SmtpClient smtpClient = new SmtpClient())
{
    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 587;
    smtpClient.Credentials = new NetworkCredential("username", "password");
    smtpClient.EnableSsl = true;
    smtpClient.Send(email);
}

请看NetImplicitSsl隐式SSL:

var emailer = new SmtpSocketClient();
emailer.Host = "your mail server address";
emailer.Port = 465;
emailer.EnableSsl = true;
emailer.User = "mail sever user name";
emailer.Password = "mail sever password" ;
emailer.AuthenticationMode = AuthenticationType.PlainText;