Configuring Postfix to use SendGrid

As I mentioned before not all Azure Subscriptions allow you to send email on port 25, this is to stop spammer from using the Azure services to send out their “junk”. If you want to send email out of WordPress is to do one of 2 things:

  1. Use a plugin inside WordPress
  2. Configure Postfix to use SendGrid

There is the option in the Azure Portal to setup a SendGrid account in the Azure Market Place.

SendGrid offers 3 Pricing Tiers:

clip_image001[4]

For my Azure usage the free tier is more than enough

create a new account in Azure if you do not already have one:

clip_image001

Fill in all the required details and then click on the Create button.

Whilst the SendGrid account is creating log on to the Ubuntu server and edit the Postfix.cf file:

sudo nano /etc/postfix/main.cf

Add the following to the config file:

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

clip_image001[6]

Create an API key in your Sendgrid account

Go to manage the SendGRid account from Azure:

image

In the settings menu click on the API Keys option:

image

Once in there click on Create

Give the API Key a name and set it to Restricted Access :

image

you only need to select Mail Send:

image

Click on Create & View

image

Copy the key to notepad or somewhere

create the sasl_passwd file by running:

sudo nano /etc/postfix/sasl_passwd

add the following line:

[smtp.sendgrid.net]:587 apikey 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

image

then secure the file by running the following:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Then restart the postfix service

sudo service postfix restart

And thats it your postfix is now configured to send email through SendGrid. Again be sure to note the IP address that your messages are being sent out from so that you can add to your SPF record if needed.

Leave Comment

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