Mail Kit 包连接方法抛出操作超时异常,但 EASendMail 包在 .Net 应用程序中成功发送具有相同属性的电子邮件。您可以在下面看到编写的 C# 代码。
var host = "mail.company.com";
var port = 25;
var userName = "username";
var domain = "domain";
var password = "password";
var senderEmail = "[email protected]";
var senderName = "Sender Name";
MailKit:
var message = new MimeMessage();
message.From.Add(new MailboxAddress("", senderEmail));
message.To.Add(new MailboxAddress("","[email protected]"));
message.Subject = "test email";
MailKit.Net.Smtp.SmtpClient smtp = new MailKit.Net.Smtp.SmtpClient();
BodyBuilder body = new BodyBuilder();
smtp.ServerCertificateValidationCallback =
(s, certificate, chain, sslPolicyErrors) => true;
smtp.Connect(host,port,SecureSocketOptions.Auto);
smtp.Authenticate(userName, password);
smtp.Send(message);
EA发送邮件
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = senderEmail;
oMail.To = "[email protected]";
oMail.Subject = "test email for test";
oMail.TextBody = "testBody";
SmtpServer oServer = new SmtpServer(host,port);
oServer.User = userName;
oServer.Password = password;
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
oServer.Protocol = ServerProtocol.ExchangeEWS;
EASendMail.SmtpClient oSmtp = new EASendMail.SmtpClient();
oSmtp.SendMail(oServer, oMail);
有什么想法吗?
我希望通过邮件套件发送电子邮件。另外,我尝试使用 System.Net.Mail 发送电子邮件,但它再次出现超时异常。
MailKit 和 System.Net.Mail 失败,因为您正在使用 SMTP 协议。
它可以与 EASendMail 配合使用,因为您使用的是 EWS 协议而不是 SMTP:
oServer.Protocol = ServerProtocol.ExchangeEWS;
这表明您的 Exchange 服务器上的 SMTP 协议已禁用。