2

My requirements are:

  • send an email from the terminal (for the sake of batch processing)
  • attach a pdf file to that email (the pdfs would be identical for all recipients, except for a watermark)
  • specify a reply-to address (myusername@gmail.com)

I've tried the "simplest answer to sending one-line messages via gmail is to use ssmtp", and several variants, and keep getting:

laptop sSMTP[19226]: Authorization failed (535 5.7.8 https://support.google.com/mail/?p=BadCredentials d13sm3920147qkj.27 - gsmtp)

Google settings:

  • IMAP enabled
  • Allow less secure apps is ON

For each ssmtp.conf setup that I tried, I have done DisplayUnlockCaptcha just before:

$echo "Testing...1...2...3" | ssmtp myusername@gmail.com

Looking at the stated thread alone, there is no consensus as to how /etc/ssmtp/ssmtp.conf should be set up:

  • mailhub=smtp.gmail.com:587 vs 465
  • UseTLS=YES vs UseSTARTTLS=Yes (or both?)
  • hostname=localhost vs whatever was put there as the default (in my case, laptop)

Could someone make a suggestion to sort this out, and possibly paste in full a working conf file?

There is a claim in a thread from 2017, that:

You can not use external applications with your normal password, you must go to https://security.google.com/settings/security/apppasswords

Is that the case? (I'm not able to do it)

What alternatives are there?

PS:

  • OS: Linux Mint 19 Tara
  • ssmtp was tested from a clean install preceded by upgrade/update
  • a couple of years ago, I was a able to send emails using the same OS (earlier version)
  • To make sure the value of AuthPass is correct, I used it to manually log into my google account.
2
  • 1
    Your authentication with Google's smtp is failing. You have to get that right before you try to send messages. Jun 27, 2020 at 19:12
  • Note at present this is required even if your account is not configured to use MFA. I tried creating a fresh account that I knew was not MFA enabled because I didn't want to have to generate an app password and I still got the same error. And, since you cannot create app passwords without MFA enabled, it looks like Google is using this requirement in an effort to combat spam/phishing (MFA uses mobile number, so links a person to the activity in many cases, or requires a would-be spammer to go to the trouble of getting access to an untraceable number if they want to remain anonymous).
    – jaredad7
    Jun 1, 2021 at 18:53

1 Answer 1

4

With the following Google settings:

IMAP enabled
Allow less secure apps is ON

The solution is to set an app-password: enter image description here

Note: App passwords setup at Google require that two-factor authentication be enabled first for the account on which you are trying to configure ssmtp for.

/var/ssmtp/ssmtp.conf:

#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
# Modified 06/27/2020:
# mailhub=mail
root=mysusername@gmail.com
AuthUser=mysusername@gmail.com
#AuthPass=[usual gmail pwd] # aint' gonna work
AuthPass=[pwd generated by https://myaccount.google.com/apppasswords]
#UseTLS=YES
#mailhub=smtp.gmail.com:465
UseSTARTTLS=Yes
mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=laptop

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

On the terminal:

$echo "Testing...1...2...3" | ssmtp recipient@gmail.com

Received in my gmailbox: enter image description here

PS:

  1. I don't see the usefulness of a vote-down without an explanation.
  2. For the second requirement stated in the question (attachment), mutt works like a charm.
1
  • In my case instead of /var/sstmp/, /etc/sstmp/
    – Erwann
    Jul 11, 2020 at 21:20

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.