c# MimeKit 邮件未正确发送。 System.Net.Mail 工作正常
c# MimeKit mail not sent without error. System.Net.Mail works fine
我制作了一个控制台应用程序来测试 MimeKit,它的执行没有错误,但电子邮件从未到达。
我使用与 System.Net.Mail 相同的数据,一切正常。
可能是什么问题?
MimeKit 代码:
var email = new MimeMessage();
email.Sender = MailboxAddress.Parse("aa@sbb.com");
email.To.Add(MailboxAddress.Parse("aa.cc@dd.com"));
email.To.Add(MailboxAddress.Parse("bb.dd@dd.com"));
email.Subject = "test";
var builder = new BodyBuilder();
builder.HtmlBody = "corpo";
email.Body = builder.ToMessageBody();
using var smtp = new SmtpClient();
smtp.Connect("smtp.xxx.com", 25, SecureSocketOptions.None);
smtp.Authenticate("ut", "pwd");
smtp.SendAsync(email);
smtp.Disconnect(true);
Console.WriteLine("Email Sent.");
System.mail代码:
using (MailMessage mm = new MailMessage())
{
mm.To.Add(new MailAddress("aa.cc@dd.com"));
mm.To.Add(new MailAddress("bb.dd@dd.com"));
mm.From = new MailAddress("aa@sbb.com", "You");
mm.ReplyToList.Add("aa@sbb.com");
mm.Subject = "vecchia mail";
mm.Body = "con system.mail";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.xxx.com";
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential("ut", "pwd");
smtp.Credentials = NetworkCred;
smtp.Port = 25;
Console.WriteLine("Sending Email......");
smtp.Send(mm);
Console.WriteLine("Email Sent.");
}
感谢@Klaus Gütter 我得到了错误然后找到了解决方案:阻止开发机器和邮件服务器之间连接的安全规则,一旦在测试环境中部署应用程序一切正常。
感谢建议
我制作了一个控制台应用程序来测试 MimeKit,它的执行没有错误,但电子邮件从未到达。
我使用与 System.Net.Mail 相同的数据,一切正常。
可能是什么问题?
MimeKit 代码:
var email = new MimeMessage();
email.Sender = MailboxAddress.Parse("aa@sbb.com");
email.To.Add(MailboxAddress.Parse("aa.cc@dd.com"));
email.To.Add(MailboxAddress.Parse("bb.dd@dd.com"));
email.Subject = "test";
var builder = new BodyBuilder();
builder.HtmlBody = "corpo";
email.Body = builder.ToMessageBody();
using var smtp = new SmtpClient();
smtp.Connect("smtp.xxx.com", 25, SecureSocketOptions.None);
smtp.Authenticate("ut", "pwd");
smtp.SendAsync(email);
smtp.Disconnect(true);
Console.WriteLine("Email Sent.");
System.mail代码:
using (MailMessage mm = new MailMessage())
{
mm.To.Add(new MailAddress("aa.cc@dd.com"));
mm.To.Add(new MailAddress("bb.dd@dd.com"));
mm.From = new MailAddress("aa@sbb.com", "You");
mm.ReplyToList.Add("aa@sbb.com");
mm.Subject = "vecchia mail";
mm.Body = "con system.mail";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.xxx.com";
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential NetworkCred = new NetworkCredential("ut", "pwd");
smtp.Credentials = NetworkCred;
smtp.Port = 25;
Console.WriteLine("Sending Email......");
smtp.Send(mm);
Console.WriteLine("Email Sent.");
}
感谢@Klaus Gütter 我得到了错误然后找到了解决方案:阻止开发机器和邮件服务器之间连接的安全规则,一旦在测试环境中部署应用程序一切正常。
感谢建议