【发布时间】:2017-07-01 02:07:16
【问题描述】:
任何人都可以帮助我如何从 Outlook 的 asp.net 核心应用程序发送电子邮件。我可以使用 MailKit 从 gmail 发送电子邮件,但使用 Outlook 失败
以下是我正在使用的代码
string FromAddress = "fromemailadress";
string FromAdressTitle = "Email from ASP.NET Core 1.1";
//To Address
string ToAddress = "Toemailadress";
string ToAdressTitle = "Microsoft ASP.NET Core";
string Subject = "Hello World - Sending email using ASP.NET Core 1.1";
string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks ( Windows, Linux, Mac ) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end.";
//Smtp Server
string SmtpServer = "smtp.live.com";
//Smtp Port Number
int SmtpPortNumber = 587;
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
mimeMessage.Subject = Subject;
//mimeMessage.Body = new TextPart("plain")
//{
// Text = BodyContent
//};
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = @"<b style='color:blue'>This is bold and this is <i>italic</i></b>";
mimeMessage.Body = bodyBuilder.ToMessageBody();
using (var client = new SmtpClient())
{
client.Connect(SmtpServer, SmtpPortNumber, false);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
client.Authenticate("Email", "Password");
client.Send(mimeMessage);
Console.WriteLine("The mail has been sent successfully !!");
Console.ReadLine();
client.Disconnect(true);
}
它的抛出错误 smptp 服务器意外断开
【问题讨论】:
-
一些代码将有助于我们提供解决方案。
-
Outlook 与这些有什么关系?
-
这个问题与桌面Outlook应用无关,而是与Outlook.com有关。
标签: c# mailkit asp.net-core-1.1