不能使用Gmail的SMTP从Azure云服务 [英] Cannot use Gmail smtp from Azure Cloud Service

查看:401
本文介绍了不能使用Gmail的SMTP从Azure云服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code通过Gmail的SMTP发送邮件:

My code for sending email through Gmail's 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);

在code工作在我的本地机器上,当我在Azure的发布为网站。

The code works on my local machine and when I publish at Azure as "Web Site".

但是当我在发布的云服务我得到这个异​​常:

BUT when I publish in a "Cloud Service" I get this exception:

 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

有没有什么不同,在Windows Azure的网站从云服务,可能有这样的效果呢?

Is there anything that differ a Windows Azure "Web site" from a "Cloud Service" that could have this effect?

谢谢!

推荐答案

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

Use following SMTP settings in Web.config:

<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>

我想你正在传递错误的凭据。使用您的用户名@ gmail.com后缀,并尝试设置bodyhtml属性也是如此...

I think you are passing wrong credentials. Use @gmail.com suffix in your user name and try to set bodyhtml property true also...

希望这会为你工作。它总是能正确工作,我..

Hope this will work for you.. It always work correctly to me..

请在<一个答案的评论href="http://stackoverflow.com/questions/7559431/c-sharp-cant-send-mail-in-windows-azure-via-gmail-smtp">this SO线程。

这篇关于不能使用Gmail的SMTP从Azure云服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆