如何解决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 举报,一经查实,本站将立刻删除。