Sent mail using smtp not working when deployed in microsoft windows azure c# asp.net mvc5

荒凉一梦 提交于 2019-12-25 02:11:38

问题


I've been trying unsuccessfully to get an email in my Azure Website. I can get it working on my localhost using either the GMail SMTP settings. However when deployed to my windows azure website ,even on my localhost IIS it doesn't work. none mail being sent or received!!! there is my code in web.config:

<appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <add key="Smtp_Server" value="smtp.gmail.com" />
        <add key="Smtp_Port" value="587" />
        <add key="Smtp_UserName" value="*****" />
        <add key="Smtp_Password" value="***" />
        <add key="Smtp_bSSLConnection" value="True" />
        <add key="ActiveSendMail" value="False" />
        <add key="SecurityKey" value="****" />
      </appSettings>

When i was searching i found a link that told me that "SMTP is not supported by Azure : http://www.postseek.com/meta/488719217d716a4fc35c7d6f336e263c" I want to know is that correct?? Would i use another sent mail server?


回答1:


SMTP probably isn't supported.

You could us Mandrill they have an api that you can use to send email that works over http, so you don't need to worry about smtp.




回答2:


Even though I logged in to my Gmail account and "white listed" my C# code hosted in Azure, Gmail kept on blocking my emails.

I opted instead to use Hotmail SMTP and use that account instead of Gmail SMTP.

ASP.NET 5 example:

public class AuthMessageSender : IEmailSender, ISmsSender <br/>
{ <br/>
    public Task SendEmailAsync(string email, string subject, string message) <br/>
    { <br/>
        var mailMessage = new MailMessage(email, email, subject, message); <br/>
        var builder = new ConfigurationBuilder(); <br/>
        var config = builder.Build(); <br/>
        var client = new SmtpClient("smtp.live.com", 587) <br/>
        { <br/>
            Credentials = new NetworkCredential("jon@doe.com", "password"),
            EnableSsl = true <br/>
        };<br/>
        client.Send(email, "ToAddress@gmail.com", subject, message); <br/>
        return Task.FromResult(0); <br/>
    } <br/>
}


来源:https://stackoverflow.com/questions/29238054/sent-mail-using-smtp-not-working-when-deployed-in-microsoft-windows-azure-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!