简体   繁体   中英

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

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM