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:



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”.


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.



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 = ""
$To = "<Your Mailaddress>"
$SMTPServer = ""
$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.

9 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:


  3. RS says:

    Thank you for this, saved me the trouble of installing XAMPP -Mercury on my Azure VM

  4. Manish Sharma says:

    Hi Admin,

    I need to configure and send mail using sendgrid from Azure SQL Managed Instance.
    I configured using below link, but still no able to send mail.

    Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

    I am able to telnet 25 also from my server.
    Can you guide me how to configure.

    Thanks in advance

    • admin says:


      Unfortunately I don’t have much knowledge in sending mail from databases, but my best guess is that there is an error in your configuration in the database.
      Have you verified that all settings are correct? I’m thinking in the last section of the post where you configure the database.

      Best regards
      Andreas Molin

Leave a Reply

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