My dad's machine has fetchmail fetching mail from various POP3 servers and sorting them into each user's mail spool, and it has sendmail to send mail using gmail's SMTP servers. This is perfectly okay, since my dad uses gmail.
Now if you go through gmail's configuration documentation, they say that you need SMTP over SSL on port 587 with TLS. They also say to use smtp.googlemail.com, but we'll ignore that, because we're not in the UK.
Setting this up requires a few simple steps.
- First, create your sendmail certificate:
cd /usr/share/ssl/certsNote that you can run
make usagein this directory for help. Also this directory is created by the openssl package, so make sure you have that.
- Next, define the SMART_HOST as esmtp:smtp.gmail.com and add certificate paths:
- Now add PLAIN and LOGIN to confAUTH_MECHANISMS so that it looks like this:
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 PLAIN LOGIN')dnlThis requires the Cyrus SASL library, which you probably already have
- You also need to create an auth-info file that looks something like this:
firstname.lastname@example.orgMake sure this file is only readable by root.
- Now regenerate everything and start sendmail. On RedHat based systems, this is as easy as running
/etc/init.d/sendmail restart. On other systems you may have to run
makefirst (or you may not have to use sendmail at all :)
Unfortunately, all doesn't go well. Mails don't go out, and in /var/log/maillog, you get errors saying "smtp.gmail.com: No route to host". You can try a traceroute and a ping, and they'll both succeed.
The problem is with that port 587 thing. For whatever reason, sendmail keeps trying port 25 even though 587 is the specified mail submit port, and sometime in the last few days or weeks, gmail stopped accepting mail submits on port 25 (at least that's what it looks like).
So, get back to your config file. This time I didn't know what options to use, but I know more or less what the sendmail.cf syntax means, and how to edit that file, so I edited it directly.
I went down to the line that starts with
Mesmtp, and looked for the line below that which said
TCP $h, which basically means connect using TCP to the host specified in $h. We need to add the port to this line. Change the line to
TCP $h 587and we're done.
Restart sendmail, and all works.
But this isn't a good solution, because the next time you regenerate sendmail.cf from sendmail.mc, your change will be overwritten.
So, what I did next, was go into /usr/share/sendmail-cf and run
grep -r '^Mesmtp' *. The result which stood out was the mailer file. Inside that file, I saw that the
TCP $hline was being added by the macro ESMTP_MAILER_ARGS, so, I just needed to add this one line after the SMART_HOST:
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnland we're done. Restart sendmail, and the config changes are permanent. All works, and mails go out.