Office365 和 smtpClient (C#) 需要帮助

问题描述

我一点运气都没有……我将 Office365 与 GoDaddy 一起带来了,我正在尝试在 Azure 函数 (C#) 上设置 smtpClient - 我已经联系了 GoDaddy 以启用 SMTP,显然他们已经这样做了。虽然登录时我似乎无法对其进行身份验证。

场景:在我的网站上创建一个联系表单,让 smtpClient 使用输入的数据和我的电子邮件发送一封电子邮件,并通过身份验证。

我必须强调,我已经 100% 正确输入了我的电子邮件和密码,甚至将它们复制并粘贴到我的浏览器中,然后以这种方式在线登录办公室。

下面是我的代码

 public async Task<bool> SendEmail(SendEmailRequest emailContent)
    {
        string petPawtiqueEmail = "**********"; // hidden for security
        string petPawtiquePassword = "**********"; // Hidden for Security
        string petPawtiqueHost = "smtp.office365.com";

        MailAddress to = new MailAddress(emailContent.EmailAddress);
        MailAddress from = new MailAddress(petPawtiqueEmail);

        MailMessage message = new MailMessage(from,to);
        message.Subject = emailContent.Subject;
        message.Body = emailContent.Message;

        SmtpClient client = new SmtpClient(petPawtiqueHost,587)
        {
            UseDefaultCredentials = false,TargetName = "STARTTLS/" + petPawtiqueHost,Credentials = new NetworkCredential(petPawtiqueEmail,petPawtiquePassword),EnableSsl = true
        };

        try
        {
            client.Send(message);
            return true;
        }
        catch (SmtpException exception)
        {
            _logger.LogError("Error occured trying to SendEmail in EmailClient",exception);
            throw exception;
        }
    }

这是我得到的例外

exception = {System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [LNXP265CA0009.GBRP265.PROD.OUTLOOK....

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)