猿问

如何使用.NET Framework通过SSL SMTP发送电子邮件?

如何使用.NET Framework通过SSL SMTP发送电子邮件?

有没有办法让.NET Framework通过端口465上的SSL SMTP服务器发送电子邮件?


通常的方式:


System.Net.Mail.SmtpClient _SmtpServer = new System.Net.Mail.SmtpClient("tempurl.org");

_SmtpServer.Port = 465;

_SmtpServer.EnableSsl = true;

_SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");

_SmtpServer.Timeout = 5000;

_SmtpServer.UseDefaultCredentials = false;


MailMessage mail = new MailMessage();

mail.From = new MailAddress(from);

mail.To.Add(to);

mail.CC.Add(cc);

mail.Subject = subject;

mail.Body = content;

mail.IsBodyHtml = useHtml;

_SmtpServer.Send(mail);

超时:

System.Net Verbose: 0 : [1024] SmtpClient::.ctor(host=ssl0.ovh.net, port=465)

System.Net Information: 0 : [1024] Associating SmtpClient#64923656 with SmtpTransport#44624228

System.Net Verbose: 0 : [1024] Exiting SmtpClient::.ctor()  -> SmtpClient#64923656

System.Net Information: 0 : [1024] Associating MailMessage#17654054 with Message#52727599

System.Net Verbose: 0 : [1024] SmtpClient#64923656::Send(MailMessage#17654054)

System.Net Information: 0 : [1024] SmtpClient#64923656::Send(DeliveryMethod=Network)

System.Net Information: 0 : [1024] Associating SmtpClient#64923656 with MailMessage#17654054

System.Net Information: 0 : [1024] Associating SmtpTransport#44624228 with SmtpConnection#14347911

System.Net Information: 0 : [1024] Associating SmtpConnection#14347911 with ServicePoint#51393439

System.Net.Sockets Verbose: 0 : [1024] Socket#26756241::Socket(InterNetwork#2)

System.Net.Sockets Verbose: 0 : [1024] Exiting Socket#26756241::Socket() 

System.Net.Sockets Verbose: 0 : [1024] Socket#23264094::Socket(InterNetworkV6#23)

我搜索了一下,发现System.Net.Mail支持端口587上的连接(显式SSL的默认端口,未加密,然后发出STARTDLS,然后切换到加密连接:RFC 2228),但不支持隐式SSL(整个连接)被包裹在SSL层中)...



holdtom
浏览 1503回答 3
3回答
随时随地看视频慕课网APP
我要回答