Sunday, February 8, 2015

Sending email via MailGun SMTP from Debian / Ubuntu Server

The following guide is a quick easy how-to use Postfix SMTP server to send outgoing mails from your Debian / Ubuntu server via Mailgun (Rackspace)


INSTALL POSTFIX AND LIBSASL

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


DISABLE EXIM4 FROM BOOT

insserv -r exim4   (remove exim4 for boot)


CONFIGURE POSTFIX

nano /etc/postfix/main.cf

remark the 'relayhost = '

add the following:

smtp_sasl_auth_enable = yes
relayhost = smtp.mailgun.org            
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd


SET SMTP LOGIN CREDENTIALS

echo 'smtp.mailgun.org username@domain.com:yourMGPassword' > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd


RESTART POSTFIX

service postfix restart


TEST FROM CLI

echo "My message body" | mail -s "Test Email" <your@emailaddress.com>

1 comment: