无法使用Azure云服务中的Gmail smtp

Cot*_*ten 12 .net gmail smtp azure

我通过Gmail的smtp发送电子邮件的代码:

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("my_user_name", "my_password");

MailMessage message =
     new MailMessage(new MailAddress("from...@gmail.com"), new MailAddress("to...@gmail.com"));
message.Body = "body";
message.Subject = "subject";
client.Send(message);
Run Code Online (Sandbox Code Playgroud)

代码在我的本地计算机上运行,​​当我在Azure上发布为"Web站点"时.

但是当我在"Cloud Service"中发布时,我得到了这个例外:

 System.Net.Mail.SmtpException: The SMTP server requires a secure connection
 or the client was not authenticated. The server response was:
 5.5.1 Authentication Required. Learn more at
Run Code Online (Sandbox Code Playgroud)

Windows Azure"网站"与"云服务"有什么不同可能产生这种影响吗?

谢谢!

Jed*_*Jed 12

我遇到了这个确切的问题.但是,我遇到了问题,无论我使用的是<system.net>配置设置,而且我使用的是正确的凭据,主机,端口等.

问题是Google拒绝了来自Azure的身份验证请求.我通过登录我在代码中用于SMTP客户端的Gmail帐户找到了这个.登录Gmail帐户后,我注意到有一个红条标题警告

有人从您帐户不常见的位置登录.如果不是您,请立即更改密码.

除了警告,我收到一封电子邮件说:

最近有人尝试使用某个应用程序登录您的Google帐户xxxxx@gmail.com.如果这是一名试图访问您帐户的劫机者,我们会阻止登录尝试.请查看登录尝试的详细信息:

  • 格林尼治标准时间周一,2012年8月27日下午10:33:59
  • IP地址:168.62.48.183
  • 地点:美国

如果您无法识别此登录尝试,则其他人可能会尝试访问您的帐户.您应该立即登录您的帐户并重置密码.请访问 http://support.google.com/accounts?p=reset_pw了解具体方法

如果是您,并且您希望此应用程序可以访问您的帐户,请完成http://support.google.com/mail?p=client_login中列出的问题排查步骤

此致,Google客户团队

在我按照提供的链接中列出的步骤操作后,我的Azure网站能够成功登录我的Gmail帐户并使用Gmail作为SMTP客户端.


Nir*_*ngh 8

在Web.config中使用以下SMTP设置:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="Network">
            <network defaultCredentials="false" enableSsl="true" host="smtp.gmail.com" port="587" userName="xxxxxxx@gmail.com" password="xxxxxxxxxxx"/>
        </smtp>
    </mailSettings>
</system.net>
Run Code Online (Sandbox Code Playgroud)

我认为你传递了错误的凭据.在您的用户名中使用@ gmail.com后缀并尝试将bodyhtml属性设置为true ...

希望这对你有用..它总是对我有用..

检查此SO线程中的答案评论.


chi*_*ef7 5

按照 Google 故障排除页面上的说明,转到以下链接并从我的本地计算机登录修复了从 Azure 网站为我发送电子邮件时的错误。

http://www.google.com/accounts/DisplayUnlockCaptcha