/ devops

Send emails through Mailgun SMTP on CentOS 7

Install the dependencies:

$ yum install postfix cyrus-sasl-plain cyrus-sasl-md5 mailx -y

In /etc/postfix/main.cf, append the following to the end of file:

relayhost = smtp.mailgun.org
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_sasl_mechanism_filter = AUTH LOGIN

Run the following to configure the authentication details:

$ echo 'smtp.mailgun.org [email protected]<mailgun_host>:<mailgun_credentials>' > /etc/postfix/sasl_passwd
$ chmod 600 /etc/postfix/sasl_passwd
$ postmap /etc/postfix/sasl_passwd
$ systemctl restart postfix

And finally test it out!

$ mail -s "Test mail" [email protected] <<< "A test message using Mailgun"
$ cat /var/log/maillog


Birkhoff Lee

Birkhoff Lee

I'm Birkhoff Lee, a developer since the age of 7. I'm still learning cyber security and site reliability engineering. Recently having Harvard CS50.

Read More