Invoke-RestMethod -Method Post -Uri $mailApiUri -Body $mailbody -Headers $headers -ContentType application/jsonĪfter running the PowerShell code above, check the recipient’s mailbox and confirm that it received the test message. $mailMessage = "This is a test message from Azure via SendGrid API" $mailSubject = "This is a test message from Azure via SendGrid API" Refer to the comments to understand what each line of code does. Then, run the code in your PowerShell session. Copy the code below and change the $sendGridApiKey, From, To, and Body values. The script below will send an email through the SendGrid SMTP relay. In this example, the authorized sender is.
The password to use is the value of the API key you created in SendGrid.The username used for SMTP authentication is always apikey.In this section, you are going to use PowerShell to send emails from an Azure VM.īefore running any code, you should know these requirements. It is time to test whether the SendGrid SMTP relay service works. Now you have the required components (account, sender, and key) to use SendGrid to send Azure emails. Saving the new SendGrid API key Sending an Email from Azure using SendGrid SMTP Relay
On the Welcome page, click on the Create a Single Sender button.Follow the instructions below to create the single sender identity. Only the verified sender address will be allowed to send messages through SendGrid’s service. In this example, you will create a single sender identity that will serve as your sender address.
There are two options authenticate a single sender (e.g., ) or authenticate an entire domain (e.g., ). Creating a SendGrid Sender IdentityĪfter creating the SendGrid account, the next step is to authorize the sender’s identity. Make sure to follow the instructions accurately. You will be asked to enable Two-Factor authentication during your first log in.
They may need to ask some verification questions before they unlock your access. When you first log in to SendGrid, you may get an error saying, “You are not authorized to access SendGrid please contact Support.” When this happens, open a ticket with SendGrid support. Then, accept the terms and click on the Create Account button. Enter your email address and your chosen password. Go to the Sign-up page, and you should see the form as shown below. Using SendGrid’s services requires you to have a SendGrid account first. You will then have access to SendGrid’s SMTP relay service or Email API to send emails from an Azure app or VM. Azure and SendGrid are so popular because there used to be a free plan with 25,000 emails per month limit to Azure customers.Īlthough the free plan is no longer being offered in the Azure portal, as confirmed by Microsoft, it is possible to sign-up for a free subscription with 100 emails per day limit. SendGrid is probably the most popular email service option for sending emails from Azure. Related: Which Azure Email Service to Choose for 2021 Using SendGrid Additional email services used as examples are Office 365 SMTP relay and Microsoft Graph API. SendGrid is an example of a third-party email service used in this article. Whichever email service you choose, using them to send emails from Azure is similar server address and port for SMTP and API endpoint address for REST. Some of the prominent names are SendGrid, MailJet, and MailGun. There are several cloud email services available to use. Knowing Which Email Services to Use with Azure to Send Emails As much as possible, use a sender email address that uses a domain that you own. Using a free email address domain, such as, is not recommended.
Refer to Create a Windows virtual machine in the Azure portal to learn how to create a new VM if you don’t have one yet.
You may register for a free trial Azure subscription if you don’t have one yet. This article is a How-To, and if you plan to follow the examples as they progress, there are some requirements you must meet.