Sending Email from Azure using Exchange Online


One of the major issue in having a LOB hosted in Azure was the that Azure does not have a SMTP server available on the cloud.

You would be used to using System.Web.Mail from your application to send mails but this requires a SMTP server the application can connect to. This is the part which is not available in Azure. But the ship is still afloat!!

You could do one of there:

  • Talk to 3rd party providers who can help sending emails
  • Connect to you on-premise SMPT servers / Email Forwarders
  • Use APIs / Services exposed by mail servers to send mails.

The 3rd approach could possibly be the best way to implement this as you can leverage Exchange Online services. claims, all you need to pay is $5 per user per month and considering the minimum you go for is a 5 user package, you are still paying 25 $ a month which works out pretty economical considering the advantages you get like:

  • Improved e-mail security
  • "From virtually-anywhere" access to e-mail for your employees
  • Enhanced operational efficiency for your IT staff
  • 25-gigabyte (GB) mailbox storage per standard license

Exchange online also exposes web services which you could use within your Azure application to send emails.

Here is what you need to do to get things going.

Get a Trial Subscription for Exchange Online. Create user accounts and remember the username, password.

Next you need to connect to Exchange Webservices. how do you the address of that? here they are:

Add to service reference to your Azure project and you are all ready to use the APIs to Read/Write/Monitor mails and mailboxes.

Wondering what the code should be? Here you go:

                var Username = RoleEnvironment.GetConfigurationSettingValue("EWSUserName");
                var Password = RoleEnvironment.GetConfigurationSettingValue("EWSPassword");

                var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Url = new Uri("");
                service.Credentials = new WebCredentials(Username, Password);

                var message = new EmailMessage(service);
                message.From = new EmailAddress(txtFrom.Text);
                message.Subject = txtSubject.Text;
                message.Body = new MessageBody(BodyType.HTML, txtBody.Text);


                lbStatus.Text = "Mail send sucessfuly to " + txtTo.Text + "..";

Here is the sample I had created to test this.

Happy Coding !!

Comments (2)
  1. Martijn van Halen says:

    Nice one. Combining Azure & BPOS. Just good for me. I'll try this out.

  2. Martijn van Halen says:

    Integrated it in our Azure Website and it works. For Europe use…/exchange.asmx

    Thanks Ranjith,

    Greetings from Spain.

Comments are closed.

Skip to main content