Skip to content

Instantly share code, notes, and snippets.

@sybarite
Created June 26, 2012 09:49
Show Gist options
  • Save sybarite/2994745 to your computer and use it in GitHub Desktop.
Save sybarite/2994745 to your computer and use it in GitHub Desktop.
Sendmail setup with mailtrap.io

Steps to setup mailtrap.io with your sendmail in ubuntu

Install sendmail and mailutils in ubuntu 'apt-get install sendmail mailutils'

In the terminal go into root prompt with sudo -s

Go to the /etc/mail folder

Make a backup of your original sendmail.cf and sendmail.mc files

Make a copy of the sendmail.mc file to sendmail-mailtrap.mc file with the command

cp sendmail.mc sendmail-mailtrap.mc

Make a directory called auth in the /etc/mail with command mkdir /etc/mail/auth

Inside the auth directory type the command echo 'AuthInfo:mailtrap.io "U:root" "I:mailtrap-username" "P:mailtrap-password' > mailtrap-info

Then type the following command makemap -r hash mailtrap-info.db < mailtrap-info

Go back to the /etc/mail folder and open the sendmail-mailtrap.mc file with your fav text editor

And paste this code before the MAILER_DEFINITIONS line

dnl # GMAIL FORWARDING
define(`SMART_HOST',`[mailtrap.io]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 2525')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/auth/mailtrap-info.db')dnl

Make sure the port number given in the settings of your mailtrap account matches the one you are defining here in the RELAY_MAILER_ARGS and ESMTP_MAILER_ARGS constants

After this save the file and type this command

m4 sendmail-mailtrap.mc > sendmail.cf

If you are done till here restart the sendmail service with

service sendmail restart

To test if send mail is working with mailtrap try the command

mail -s "Testing new Gmail Forwarding" SOMEUSER@gmail.com
Blah Blah Blah
^D (This is control+d)

You should be able to see this mail in your mailtrap inbox

@alexbowers-tecmark
Copy link

This line: echo 'AuthInfo:mailtrap.io "U:root" "I:mailtrap-username" "P:mailtrap-password' > mailtrap-info is missing a closing double quote.

echo 'AuthInfo:mailtrap.io "U:root" "I:mailtrap-username" "P:mailtrap-password"' > mailtrap-info

is correct.

@antongorodezkiy
Copy link

For centos users like me, you'll also need to install sendmail itself, mail and yum install cyrus-sasl*.
Do not forget to restart sendmail after installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment