最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Exchange Server Timout issue in .Net Mail Kit - Stack Overflow

programmeradmin13浏览0评论

Mail Kit package connect method throw operation timeout exception but EASendMail package send email successfully with same properties in .Net app. You can see written c# code under below.

var host = "mailpany";
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);

EASendMail

 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);

Any idea?

I expected email sent with Mail kit. In additional I tried send email with System.Net.Mail but its give timeout exception again.

Mail Kit package connect method throw operation timeout exception but EASendMail package send email successfully with same properties in .Net app. You can see written c# code under below.

var host = "mailpany";
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);

EASendMail

 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);

Any idea?

I expected email sent with Mail kit. In additional I tried send email with System.Net.Mail but its give timeout exception again.

Share Improve this question asked Nov 18, 2024 at 13:03 mertkmertk 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

It's failing for MailKit and System.Net.Mail because you are using the SMTP protocol for those.

It works with EASendMail because you are using the EWS protocol instead of SMTP:

oServer.Protocol = ServerProtocol.ExchangeEWS;

This suggests that the SMTP protocol on your Exchange server is disabled.

发布评论

评论列表(0)

  1. 暂无评论