1

I am struggling to get my SMPT emails to work in Azure Websites. This works on my local setup:

 <mailSettings>
  <smtp deliveryMethod="Network">
    <network host="relay.myIsp.net" userName="" password="" port="25" />
  </smtp>
</mailSettings>

I have changed my ISP's name to "myIsp", apart from that it is the same.

I have read a few posts about conflicting Azure.config , but I cannot find it.

I am using ActionMailer.Net, which seems great, as my Email message producer.

The application does follow through, no errors. I just get no email.

Thanks in advance.

EDIT:

SendGrid Web.config setup, so port 25 or 587 no issue on Azure Websites:

   <system.net>
    <mailSettings>
      <smtp from="test@domain.com">
        <network host="server" password="password" userName="username" port="587" />
      </smtp>
    </mailSettings>
  </system.net>
SamJolly
  • 6,347
  • 13
  • 59
  • 125
  • It's going to be that the port is blocked to azure websites. You'll (probably) have to contact their support about this and possible alternatives :/ –  Apr 21 '14 at 14:10
  • Thanks for this. It seems that there is no way for the application to send emails using the using internal .NET components on Azure Websites. Both port 25 and 587 seem blocked. Is this right? Is it correct the only way to email from an application hosted on Azure Websites is to use a 3rd party service such as SendGrid or an email relay service setup on Azure Cloud services? – SamJolly Apr 21 '14 at 14:46
  • Not sure, but I am sure that ports are highly regulated for azure websites. –  Apr 21 '14 at 14:56
  • 1
    AFAIK, azure websites does not block port 25 or 587 (SendGrid works on those with no issue). I would however have to think that your configuration is not correct, an SMTP server that allows sending without credentials is usually a big security lapse. Are you sure you don't have / need a username and password? Also, it may work on your local setup simply because you are connected via your ISP, so they know its an ok connection. Have you tried with a gmail / hotmail account? I would start with trying a new email account as I have a feeling this is an issue with your ISP relay – Tommy Apr 21 '14 at 15:37
  • Example of a gmail account setup: http://stackoverflow.com/a/11020017/130387 – Tommy Apr 21 '14 at 15:38
  • Hi @Tommy, Just been thinking this exact same thought. Yes, from my local connection they have everything, whereas from Azure they have a strange dynamic IP and no credentials. Also I pick up the same information on SendGrid which I have added under EDIT. Thanks for the post. Very helpful – SamJolly Apr 21 '14 at 15:59
  • Ok, got this working now. Needed username and password and SSL setting to false. I think I will end up using SendGrid due to the close relationship with Azure. Tommy if you want to format as answer then I will mark as such. Thanks. – SamJolly Apr 21 '14 at 16:35
  • @SamJolly - just saw your last comment, done! Btw, if you preface your comment with `@username` (eg `@Tommy`), it will flag a notification to the user in the top bar :) – Tommy Apr 21 '14 at 18:57

2 Answers2

2

As far as I am aware, Azure websites and web roles do not block port 25 nor port 587 as SendGrid and other email accounts I have tried work without issue using these ports.

However, looking at your configuration, I suspect that the lack of a username and password could be the cause. Having an open relay for sending email is a big security lapse (think spam gateway). Typically, you have to authenticate to the email server in order for it to send email. As for it working from home, this may work simply because you are connecting through them to the email server (you are on your ISP's modem and IP subnet) and they automatically know it is an OK connection.

For troubleshooting, I would recommend trying with a SendGrid or Gmail account. If that works, then it will point you to a configuration issue with your ISP.

Example Gmail Configuration:

<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>
Tommy
  • 39,592
  • 10
  • 90
  • 121
0

You just need to include variables inside the of your web.config as follows:

<!-- SendGrid-->
<add key="mailAccount" value="azure_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX@azure.com" />
<add key="mailPassword" value="XXXXXXXXXXXXXXX" />

Then on setting the credentials for sending the email set it as follows:

var credentials = new NetworkCredential(
                   ConfigurationManager.AppSettings["mailAccount"],
                   ConfigurationManager.AppSettings["mailPassword"]
                   );
Jay
  • 3,012
  • 14
  • 48
  • 99