A question popped up today about sending emails from within the Windows Azure environment, specifically using SmtpClient.

So, to cover off some basics:

  1. The Windows Azure environment itself does not currently provide a SMTP relay or mail relay service
  2. .NET applications run under a variation of the standard ASP.NET medium trust policy called Windows Azure Trust policy
  3. Port 25 is open (well, all ports are open actually) to outbound traffic for Windows Azure applications

As we don't provide a host for sending or relaying SMTP mail messages, you'll need to find one that will. Your ISP or free mail provider will do providing they are setup to enable SMTP relaying.

Next, there is an issue with using the SmtpClient class with its Port property set to something other than 25 and its trust election, see this forum thread:

So to demo this, I whipped up a quick sample app that sends STMP emails through a relay host as a web role:

image

The code is here:

And the app is deployed here:

Enjoy :)