几个月前我在Azure网站上部署了一个应用程序,它已按预期工作。昨天,微软发布了一系列新功能后,我注意到有一个选项可以从32位更改为64位。我将网站配置从32位更改为64位。所有网站都有效,除非我尝试使用标准SMTP .NET库通过SendGrid发送电子邮件。
这是我得到的例外:
访问被拒绝“source =”System“detail =” System.Net.NetworkInformation.NetworkInformationException (0x80004005):系统中的System.Net.NetworkInformation.SystemIPGlobalProperties.GetFixedInfo()拒绝访问位于System.Net.Mail.SmtpClient.ctor()的System.Net.Mail.SmtpClient.Initialize()的System.Net.NetworkInformation.SystemIPGlobalProperties.get_HostName()处的.Net.NetworkInformation.SystemIPGlobalProperties.get_FixedInfo()
这是代码:
var toAddress = new MailAddress(to, username);
using (var smtp = new SmtpClient())
using (var message = new MailMessage() {Subject = subject, IsBodyHtml = true})
{
message.To.Add(toAddress);
message.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html));
smtp.Send(message);
}
的Web.config:
<system.net>
<mailSettings>
<smtp from="xxx@xxx.com">
<network host="smtp.sendgrid.net" port="587" userName="xxx@azure.com" password="xxxxx" />
</smtp>
</mailSettings>
</system.net>
我的开发环境配置为64位,应用程序可以发送电子邮件。 知道为什么它在Azure 64位模式下失败了吗?
谢谢!
答案 0 :(得分:0)
我遇到了这个问题,发现我在web.config文件和Azure应用设置中存在冲突的值。我不确定这些在Azure中是如何工作的,因为它们似乎没有直接映射到web.config应用程序设置。删除所有Azure应用程序设置(并离开web.config)后,通过gmail发送的电子邮件没有问题。