【问题标题】:How to send email from outlook using asp.net core 1.1如何使用 asp.net core 1.1 从 Outlook 发送电子邮件
【发布时间】: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


【解决方案1】:

您很可能遇到了 NTLM 身份验证代码中的错误,该错误似乎不适用于某些版本的 Exchange。

您可以通过以下方式禁用 NTLM 身份验证:

client.AuthenticationMechanisms.Remove ("NTLM");

在调用 Authenticate 方法之前调用它,你可能会没事的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多