Configure Postfix to sent emails using MailGun

First install requirements

apt-get update && apt-get install postfix libsasl2-modules -y

Run

sed -i "s/default_transport = error/# default_transport = error/g" /etc/postfix/main.cf
sed -i "s/relay_transport = error/# relay_transport = error/g" /etc/postfix/main.cf
sed -i "s/relayhost =/# relayhost =/g" /etc/postfix/main.cf

Edit /etc/postfix/main.cf

Advertisement

vi /etc/postfix/main.cf

Add

relayhost = [smtp.mailgun.org]:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

Create file /etc/postfix/sasl_passwd

echo "[smtp.mailgun.org]:2525 SMTP_LOGIN:SMTP_PASSWORD" > /etc/postfix/sasl_passwd

Replace SMTP_LOGIN and SMTP_PASSWORD with your user and password you get from mailgun.

Run

postmap /etc/postfix/sasl_passwd

Restart postfix

service postfix restart

You can test email with

echo "test" | mail -s "test" admin@serverok.in
Add a comment

Leave a Reply

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

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement