Configuring Gmail as Sendmail email relay - LinuxConfig.org


#1
In this configuration tutorial we will guide you through the process of configuring sendmail to be an email relay for your gmail or google apps account. This allows you to send email from your bash scripts, hosted website or from command line using mail command.
This is a companion discussion topic for the original entry at https://linuxconfig.org/configuring-gmail-as-sendmail-email-relay

#2

rascal

Any way to change sender name from root to something else (debian 9)?


#3

Mega Dimka -> rascal

in gmail-auth, change U:root to U:username


#4

James

I have this running from the command line. I run a test from the command line like so:

“echo “Just testing my sendmail gmail relay” | mail -s “Sendmail gmail Relay” my-email@my-domain.com

There is a delay, but it does eventually send the email…

When I call mail() from php, it’s timing out or dying with a “504 Gateway Time-out” error.

In the article it says “If you will experience substitutional delays after executing the above command to most likely cause is that you have not configured your host with FQDN. Check your logs for a warning:”

I don’t find anything in the logs. I have restarted the server, but can’t think of anything else to try… I believe the hosts are configured properly with:

127.0.1.1 server-name
127.0.0.1 localhost

I’m not sure what else to try at this point…

Any tips ideas or advice?


#5

Roy MoreLeSter

There is no “makemap” for Fedora


#6

bonobo2000

I dont undestand all what I did but worked perfectly, thanks. had to generate and use a one-usage password from google, as I am used two-step verificiation.


#7

SP

I followed the post but i see following error :

Jan 25 15:11:34 ubuntu sendmail[4545]: v0PLBYIW004545: from=root, size=130, class=0, nrcpts=1, msgid=201701252111.v0PLBYIW004545@localhost.localdomain, relay=root@localhost
Jan 25 15:11:34 ubuntu sm-mta[4546]: v0PLBYnl004546: from=root@localhost.localdomain, size=405, class=0, nrcpts=1, msgid=201701252111.v0PLBYIW004545@localhost.localdomain, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jan 25 15:11:34 ubuntu sendmail[4545]: v0PLBYIW004545: to=shantu17@hotmail.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30130, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v0PLBYnl004546 Message accepted for delivery)
Jan 25 15:11:34 ubuntu sm-mta[4548]: STARTTLS=client, relay=gmail-smtp-msa.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-SHA, bits=128/128
Jan 25 15:11:35 ubuntu sm-mta[4548]: v0PLBYnl004546: to=shantu17@hotmail.com, ctladdr=root@localhost.localdomain (0/0), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=120405, relay=gmail-smtp-msa.l.google.com. [74.125.198.109], dsn=5.0.0, stat=Service unavailable
Jan 25 15:11:35 ubuntu sm-mta[4548]: v0PLBYnl004546: v0PLBZnl004548: DSN: Service unavailable
Jan 25 15:11:36 ubuntu sm-mta[4548]: v0PLBZnl004548: to=root@localhost.localdomain, delay=00:00:01, xdelay=00:00:01, mailer=local, pri=30000, dsn=2.0.0, stat=Sent


#8

venom

Kevin Schultz Followed your instructions. except the 3rd one since the links dead. Still cannot get mail to send, it is saying “530-5.5.1 Authentication Required”. I’ve allowed less secure apps to access my gmail account and i do not have two factor authentication. I have no idea what to do, any help would be greatly appreciated.


#9

Justin Kromlinger -> venom

You need to set up an application password.


#10

metulburr

I had to reset my gmail password. Now that i redo this process with the new password, i cant get it to work anymore


#11

Spencer Williams

Hell yeah! This worked for me in an Ubuntu (jessie) docker container on a Windows 10 host.


#12

SP -> Spencer Williams

I also used ubuntu but i see following error:
Can you help me?
Jan 25 15:11:34 ubuntu sendmail[4545]: v0PLBYIW004545: from=root, size=130, class=0, nrcpts=1, msgid=201701252111.v0PLBYIW004545@localhost.localdomain, relay=root@localhost
Jan 25 15:11:34 ubuntu sm-mta[4546]: v0PLBYnl004546: from=root@localhost.localdomain, size=405, class=0, nrcpts=1, msgid=201701252111.v0PLBYIW004545@localhost.localdomain, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jan 25 15:11:34 ubuntu sendmail[4545]: v0PLBYIW004545: to=shantu17@hotmail.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30130, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (v0PLBYnl004546 Message accepted for delivery)
Jan 25 15:11:34 ubuntu sm-mta[4548]: STARTTLS=client, relay=gmail-smtp-msa.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-SHA, bits=128/128
Jan 25 15:11:35 ubuntu sm-mta[4548]: v0PLBYnl004546: to=shantu17@hotmail.com, ctladdr=root@localhost.localdomain (0/0), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=120405, relay=gmail-smtp-msa.l.google.com. [74.125.198.109], dsn=5.0.0, stat=Service unavailable
Jan 25 15:11:35 ubuntu sm-mta[4548]: v0PLBYnl004546: v0PLBZnl004548: DSN: Service unavailable
Jan 25 15:11:36 ubuntu sm-mta[4548]: v0PLBZnl004548: to=root@localhost.localdomain, delay=00:00:01, xdelay=00:00:01, mailer=local, pri=30000, dsn=2.0.0, stat=Sent


#13

Spencer Williams -> SP

Unfortunately, I started running into problems with this setup. Sendmail seemed to have trouble properly authenticating with any mail server. I switched to a program called ssmtp, which has much simpler configuration, and got that working instead.


#14

felipem

Thanks, it’s works in my linux mint 17.2


#15

Wretched Ghost

I got it working following the How-To exactly as well as following the steps that Kevin Schultz explained. (opening 587 on firewall (i use pfsense); custom password on Google App Pass/re-run makemap; editing the host file.)


#16

Kevin Schultz

Some solutions (Note: running Debian Stretch (Testing)):

  • First, I had two sendmail.mc files: 1) /usr/share/sendmail/cf/debian/sendmail.mc ; and 2) /etc/mail/sendmail.mc . I updated them both, putting the text under “MAILER_DEFINITIONS”, but I believe you only need to update #2. Note: if you forget to update #2, and your ISP blocks outgoing port 25, you may get /var/log/mail.log error, “…status=deferred (connect to …”

  • Second, for Two Factor Authentication users, as a workaround, go to https://security.google.com… and generate an App password: select “Mail”, from pulldown “Select App”, and “Other (Custom name”), from pulldown “Select Device”, filling in whatever descriptive text, when prompted. Then select button “GENERATE”. Copy the password and replace your password, from the file created in directory /etc/mail/authinfo/, above (for example, gmail-auth). Rerun “makemap hash gmail-auth < gmail-auth” and maybe “/etc/init.d/sendmail reload” as well, for good measure.


#17

marmor

mabye my brain not working today but step 4 “right above first “MAILER” definition line:”
where exactly is that, i do not know what im looking for


#18

Kevin Schultz -> marmor

Like this (note: under “MAILER_DEFINITIONS”, but over the first “MAILER(…)”):

include(/etc/mail/m4/dialup.m4')dnl include(/etc/mail/m4/provider.m4’)dnl
dnl #
dnl # Default Mailer setup
MAILER_DEFINITIONS
define(SMART_HOST',[smtp.gmail.com]’)dnl
define(RELAY_MAILER_ARGS',TCP $h 587’)dnl
define(ESMTP_MAILER_ARGS',TCP $h 587’)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/authinfo/gmail-auth.db')dnl MAILER(local’)dnl
MAILER(`smtp’)dnl


#19

Hugo Lara Sanchez

i dont receive any mail


#20

li he -> Hugo Lara Sanchez

me too