SendGrid Postfix Rat

I often launch CentOS images on ec2, specifically the RightImage_CentOS_6.3_x64_v5.8.8.5_EBS (ami-3b7bfc52). It’s a great clean CentOS image if you need to run tests or install Kaltura on a clean machine.

A common requirement is to have an email sending service, preferably postfix that will be stable and handle long queues of emails (to support for email notifications or alerts).

According to this thread on the AWS forums, mainly to block spam, ec2 servers are by default blocked from directly sending mail over port 25. So you’re mainly left with two options:

I preferred SendGrid for simplicity and since their free tier provides free 200 emails/day.
To signup, visit: https://sendgrid.com/user/signup, new accounts are usually enabled within 5 hours.

Configure sSMTP to relay via SendGrid

The default mail service on CentOS will be ssmtp. If you need to get an email working quickly, and don’t expect significant email queues, that might be a good option. ssmtp is abandoned since 2011, so you might want to jump to the postfix section if you care for a more stable solution.

Selec All Code:
1
 

Then edit/add the following settings  (replace with your SendGrid user and pass):

Selec All Code:
1
 

To test, execute:

Selec All Code:
1
 

 

Configure Postfix to relay via SendGrid

A better option is to install Postfix, and set it to relay emails via SendGrid.

Installing Postfix:

Selec All Code:
1
 

Configuring main.cf:

Selec All Code:
1
 

At the end of the file, add the following lines (replace with your SendGrid user and pass):

Selec All Code:
1
 

Run the following commands (which will initialize the mail aliases db and restart Postfix):

Selec All Code:
1
 

Lastly, configure MTA to choose Postfix by default (select the Postfix option and press enter):

Selec All Code:
1
 

Testing Postfix

Selec All Code:
1
 

Send a test mail:

Selec All Code:
1
 

Check the log file for any errors:

Selec All Code:
1
 

If you see no errors (and you shouldn’t) in the log, your message should successfully arrive at yourname@domain.com.