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 = "firstname.lastname@example.org" $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)