1

I am using msmtp to sent emails but getting authentication error although my login credentials were right.

my msmtprc file contains

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
host smtp.gmail.com
port 25
auth on
user *******@gmail.com
password *********
from **********@gmail.com
logfile /var/log/msmtp.log

on running this command on terminal

echo -e "Subject: Test Mail\r\n\r\nThis is my first test email." |msmtp --debug --from=default -t vikrantgoutam16@gmail.com

I get the following errors

msmtp: authentication failed (method PLAIN)
msmtp: server message: 535-5.7.8 Username and Password not accepted. Learn more at
msmtp: server message: 535 5.7.8 https://support.google.com/mail/?p=BadCredentials b14sm68898705pfi.92 - gsmtp msmtp: could not send mail (account default from /etc/msmtprc)

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Yes, I've hit this obstacle too, even with 2 factor authentication and an app password, and there seems to be no solution other than allowing less secure apps (eg https://marvintan.com/posts/send-email-using-google-stmp/), which I prefer not to do... – joharr Jan 20 '20 at 22:39

2 Answers2

0

I just had the same issue. I have a Debian 10 32bit with PHP 7.3.14-1, and the /etc/msmtprc file has...

account <myusername>@gmail.com
host smtp.gmail.com
port 587
tls on
tls_starttls on
auth on
user <myusername>
password <plain-password>
from <username>@gmail.com
account default : <username>@gmail.com

This configuration sends the email with no errors using smtp.gmail.com, then I have a GCE (Google Compute Engine) with Debian 10 64bit and PHP 7.3.14-1, with the exact same configuration file and it does not work. I enabled the 2-step verification method and generated a 16 character password for my script, with the App Password, the GCE just worked. Of course the 32bit machine is not able to send emails anymore, but my priority was the GCE machine. The configuration file on GCE is...

# Set default values for all following accounts.
defaults
port 587
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account gmail
host smtp.gmail.com
from <myusername>@gmail.com
auth on
user <myusername>@gmail.com
password <16 character password from Gmail>

# Set a default account
account default : gmail

It's probably worth mention that the 32bit machine has gCloud SDK and it's fully capable of login and connect to the GCE instance.

0

Following the guide on the arch wiki I realized that I did not have chmod setting.

I technically copied and pasted the settings in the example making these changes:

  • from
  • user
  • password
  • << deleted the freemail service section >>

Once I set this parameter solution worked for me.

keelerm
  • 2,873
  • 20
  • 12
chribonn
  • 445
  • 5
  • 20