I would like to use the regular mailx package's /bin/mail app to send email alerts:

echo "Testing alerts from prod server" | mail -s "Example email" user@mydomain.com

I control DNS for mydomain.com. mydomain.com also uses Google Apps.

It seems Google Apps doesn't generally deliver email from random SMTP clients. What's the best way to make Google apps 'trust' my Unix servers to send mail?

  • Don't you have a way to authenticate to Google Apps? I'm not very familiar with how it works. With email hosting, you can authenticate to your provider - e.g. using exim. The relevant file, in Debian, at least, is /etc/exim4/passwd.client. – Faheem Mitha Feb 27 '16 at 14:09
  • 1
    Shouldn't this question better be asked on Server Fault? – Murphy Feb 27 '16 at 17:07
  • 1
    @Murphy I doubt it, SF takes “professional” very seriously and would probably shoot down this question. Maybe Web Applications would help. “How do I authenticate to Google Apps” is a Webapps question, “How do I implement Google Apps authentication on Unix” is a Unix question, but it's the same question either way... mikemaccana: if you don't get useful answers here, you can flag your question and request a migration to Web Applications; they might not know what tool to use on Unix but they should at least know what protocol that tool needs to implement. – Gilles 'SO- stop being evil' Feb 28 '16 at 19:13
  • @FaheemMitha This is the way to do it. You should make a full answer from this. – Michael Hampton Feb 28 '16 at 19:32
  • @MichaelHampton Done. Thank you. This is not something I know much about, so please suggest improvements/corrections as appropriate. – Faheem Mitha Feb 28 '16 at 21:09

You probably need to set up authentication to your smarthost to send email. In this case, the smarthost is presumably some Google server.

Roughly speaking, the way this works is

mail -----------> local mailserver ----------------> remote smarthost

That is, the local mailserver receives the message from the client program (e.g. mail), then authenticates and delivers to the remote smarthost.

You don't state which mail server you are using locally, but I'll use the example of Exim. In the case of Exim, you need to add an entry to the /etc/exim4/passwd.client password file. Here is the default state of that file.

# password file used when the local exim is authenticating to a remote
# host as a client.
# see exim4_passwd_client(5) for more documentation
# Example:
### target.mail.server.example:login:password

Per the comment, man 5 exim4_passwd_client has more information.

I think most distributions set up a local mailserver by default, though which one is used may vary. Debian and therefore probably Ubuntu set up Exim by default. Note that even the mailserver is installed, it may not be set up to connect to a smarthost by default.

If a local mailserver isn't installed, you should install one. Some programs can authenticate and deliver to a smarthost directly, bypassing the local mailserver, but that is not a good idea.


I had to activate the "Less secure apps" described here to make it accept eMails. But I am using a vanilla gmail account.

  • That's to sign in and check your inbox, ie POP or IMAP. The question is about SMTP clients, ie, allowing Unix hosts to send you email although they're not well known MXs. – mikemaccana Feb 27 '16 at 16:20

Sorry to revive such an old question, but it's still coming up in the search results for this issue.

What I have discovered, is that Google is now doing full "Device Management", so from every device that you want to login from you'll have to visit:


The problem is that I don't have X11 setup on my exim4 server, and I can't figure out the magic CURL formula to go to the link and pull the token that is dynamically generated when you press the "Continue" button on that URL.

Because of this, even when I have configured TLS/mta support in exim4 (SSH/smtps is no longer supported by Google), to connect to smtp.google.com:587 it will not accept my username/password without going to:


to enable access by "less secure app".

I even tested this manually via:

openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf


EHLO {servername}
AUTH PLAIN {base64 encoded combo username password string}

Every time I get the error:

535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials l22sm5213582ywl.68 - gsmtp

You get the base64 encoded string with the command:

echo -ne "\0{login_email}\0{login_password}"|base64

Once I set the "enable less secure apps" the exact example above returns:

235 2.7.0 Accepted

And, exim4 likewise starts working.

Can anyone recommend a CLI way to access the captcha link?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.