4

I am trying to send emails using the php mail(); function. I have installed msmtp to allow me to use a gmail account. However whenever I try to send test email using msmtp then a destination email, the system freezed and I cannot write more commands.

This is the contents of ~/.msmtprc:

account gmail
tls on
tls_starttls on
tls_certcheck off
auth on
logfile ~/.msmtp.log
host smtp.gmail.com
port 587
user ****@gmail.com
from ****@gmail.com
password **********

account default : gmail

Also when it does sometimes work, I get an error which says bad credentials even though the details are correct, access for less secure apps is on and there is no 2-step verification.

  • Generate Google App Password . That's how I managed to use it – sdkks Oct 24 '16 at 13:18
  • When I go to: here I get a message saying it is not available for my account. Is it because I'm not using two step verification? – Ryan Oct 24 '16 at 13:51
  • I'm already using that for security purposes, it might have an affect. Before 2FA, I used to enable a setting to allow use of less secure apps. Not sure if it's still there. – sdkks Oct 24 '16 at 13:57
  • It is and I already a have enabled it. I wrote this all down below the contents of ~/.msmtprc – Ryan Oct 24 '16 at 14:09
  • As per this article There are two ways, one is allowing less secure app, which you did, other is to use 2FA. And here it is mentioned that, although you might have enabled less secure option, password can still fail. – sdkks Oct 24 '16 at 14:50
0

If allowing less secure app doesn't work, you should consider 2FA.

Here is my working configuration:

account default
host smtp.gmail.com          
port 587                     
from "yourusername@gmail.com"   
tls on                       
tls_starttls on              
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on                     
user "yourusername"       
password "yourapppassword"       
logfile ~/.msmtp.log
  • Sadly not, still get the same error message: – Ryan Oct 24 '16 at 14:58
  • 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 j189sm15214899wmd.22 - gsmtp msmtp: could not send mail (account default from /root/.msmtprc) – Ryan Oct 24 '16 at 14:58

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.