Cannot use Gmail smtp from Azure Cloud Service(无法从 Azure 云服务使用 Gmail smtp)
问题描述
我通过 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);
代码在我的本地机器上运行,当我在 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 属性也设置为 true...
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..
在 这个 SO线程.
这篇关于无法从 Azure 云服务使用 Gmail smtp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法从 Azure 云服务使用 Gmail smtp


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01