Postfix SMTP relay configuration in Gentoo

A Postfix SMTP relay configuration can be useful in several scenarios. Sometimes, for example, I want to have some email notifications sent to my email address by my computer at home, for example to receive reports of some scheduled tasks.

The problem is that if you just install Postfix or other MTA with a default configuration, emails sent from your home computer may be flagged as spam or mailing may not work altogether due to some restrictions ISPs often have also to prevent spam.

One workaround is to configure e.g. Postfix to use an external SMTP service such as SendGrid to send the emails. Here I’ll show how to do this on Gentoo.

First thing you need to do is install Postfix. Edit /etc/portage/package.use and add:

(of course you may have to specify a different version) Then run:

I also suggest you install mailutils as this includes an utility you can use to test email sending:

Next, you need to edit /etc/postfix/sasl_passwd and add the following line which contains the address and port of the SMTP service and the credentials required for the authentication:

You need then to create a db from this file with the following command:

Also run:

Now edit /etc/postfix/main.cf and add the following:

Please note that you need to set a FQDN hostname on your computer that is already validated with the SMTP service.

Finally, restart Postfix:

You can test that mailing works with the mail utility:

To check the logs you can run:

That’s it. All emails sent from your computer will be now sent through the 3rd party SMTP service.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

About the author

Vito Botta

I am a passionate web developer based in Espoo, Finland. Besides computing, I love boxing and good food!

View all posts

Leave a Reply

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

four + 18 =