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 badge1 Answer
Reset to default 0It'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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745616344a4636260.html
评论列表(0条)