Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure中web.config中的邮件设置被忽略_Azure_Web Config_Smtp - Fatal编程技术网

Azure中web.config中的邮件设置被忽略

Azure中web.config中的邮件设置被忽略,azure,web-config,smtp,Azure,Web Config,Smtp,在Azure托管的MVC应用程序中,我的邮件设置如下 <system.net> <mailSettings> <smtp deliveryMethod="Network" from="support@smeedi.com"> <network defaultCredentials="false" host="smtp.gmail.com" userName="username@gmail.com" enableSsl="true" port=

在Azure托管的MVC应用程序中,我的邮件设置如下

<system.net>
<mailSettings>
  <smtp deliveryMethod="Network" from="support@smeedi.com">
    <network defaultCredentials="false" host="smtp.gmail.com" userName="username@gmail.com" enableSsl="true" port="587" password="password" />
  </smtp>
</mailSettings>

所有详细信息均为空,当客户端尝试发送电子邮件时,我收到一个SMTP主机未指定的异常。这只有在升级到MVC4和Azure 2.0(从Mvc 3和Azure 1.7)时才开始发生。为什么不使用config中的邮件设置?

web.config中的一个更简单的设置适合我(我使用SendGrid电子邮件应用,通过Azure门户设置为应用程序):


new SmtpClient()
调用与原始问题中给出的调用相同。它在模拟器和Azure托管的网站中都能工作


如果这个问题仅仅是由于gmail托管引起的,你也许可以试试SendGrid。Azure用户在一定程度上是免费的,并且可以直接从Azure门户内部进行设置。

此问题是在模拟器中还是在实际的Windows Azure云中发生的?我可以确认我也有此问题。邮件设置被忽略(即使使用sendgrid),SmtpClient失败,异常为System.InvalidOperationException:未指定SMTP主机。在System.Net.Mail.SmtpClient.CheckHostAndPort()中,在System.Net.Mail.SmtpClient.SendAsync(邮件消息,对象用户令牌)中,在System.Net.Mail.SmtpClient.SendMailAsync(邮件消息)中,即使设置在web.config中。
SmtpClient client = new SmtpClient();
<mailSettings>
    <smtp from="no-reply@mydomain.com">
        <network host="smtp.sendgrid.net" port="587" userName="myAzureSuppliedId@azure.com" password="password" />
    </smtp>
</mailSettings>