Configure a SMTP server in Azure

Sometimes in my scripts I need to send the result in a mail, but I don’t always have access to a SMTP server, so I decided to configure a SMTP server in Azure that I can use.

I will use SendGrid Email Delivery for this since I will get 25.000 free emails each month, more than I will ever use.

The first thing is to log on to Azure and find SendGrid Email Delivery in the market:

SendGrid

 

When you click on create you will be prompted to enter some information for the new account that will be used to access the SMTP server. Specify a name for the account, a password, resource group and select the “Free” option under “Pricing tier”.

Account

When you click on “Create” you will be sent to the dashboard and after a few minutes you will see that the account has been pined and ready for use.

If you click on the account you will be redirected to the settings-page where you will find the SMTP-address and the “real” account name that you will use to gain access to the SMTP.

Settings

 

Now you have access to a SMTP-server that you can use to send 25.000 mails through.

A simple script that you can use to test the function is posted here, just change the parts contained in <> to your own settings.

$From = "sender@test.com"
$To = "<Your Mailaddress>"
$SMTPServer = "smtp.sendgrid.net"
$SMTPPort = "587"
$Username = "<Your SendGrid username>"
$Password = "<Your SendGrid password>"
$subject = "Test"
$body = "This is a testmail using SendGrid Email Delivery"

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)

$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
$smtp.Send($From, $To, $subject, $body)

 

This entry was posted in Azure, Powershell and tagged , , , , . Bookmark the permalink.

6 Responses to Configure a SMTP server in Azure

  1. Nice article you did there!

    Just a few word to say you that Mailjet has also landed on Microsoft Azure! Do you think it could deserve another article?

    Longing for hearing from you,

    Grégory from the Mailjet team 🙂

  2. Simon Oxenbridge says:

    Hi admin,

    I’m trying to grasp an issue I am having where I need an IRM solution to classify emails but I also need the ability to send classified emails externally. Is it possible to set an Azure IRM solution up in such a way then when I send an email I get the following classification options:
    – Unclassified
    – IN confidence (cannot leave internal)
    – Restricted (cannot leave internal)
    – Restricted External (sent to external via SMTP relay)

    Any insights would be great

    • admin says:

      Hi Simon!

      This should be possible by using Azure Information Protection.
      I haven’t tried this myself, but I think it will meet your needs!

      You can read more about it here:

      //Andreas

Leave a Reply

Your email address will not be published. Required fields are marked *