Asp.Net发送Outlook电子邮件并获取此5.7.57 SMTP客户端未通过身份验证,以在MAIL FROM期间发送匿名邮件

时间:2019-01-10 15:58:30

标签: c# asp.net email outlook

我正在使用asp.net c#发送Outlook电子邮件。

运行此命令时,我在(smtp.Send(fromAddress,toAddress,subject,body);)遇到错误,我在线搜索并尝试解决问题。请发送帮助。对此,我真的非常感激。

protected void btn_Click(object sender, EventArgs e)
    {
        string eml = "xxx@mymail.com";
        var fromAddress = "xxx@outlook.com";
        var toAddress = eml;
        const string fromPassword = "password";
        string subject = "Subject testing";
        string body = "Welcome..";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient("smtp-mail.outlook.com");
        {
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.UseDefaultCredentials = false;
            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential(fromPassword, fromPassword);
            smtp.EnableSsl = true;
            smtp.Credentials = credentials;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }

1 个答案:

答案 0 :(得分:2)

在线:

new System.Net.NetworkCredential(fromPassword, fromPassword)

两个参数都具有fromPassword,而不是用户名和密码

new System.Net.NetworkCredential(fromAddress, fromPassword)