Using Gmail for sending smtp mail

Written by Robert -

Before doing any of this, make sure you allow unsafe applications to use your gmail account. I cannot advise you doing this with your normal e-mail account. You should only do this with an account dedicated for this purpose, because of the dangers of having SMTP open.

After being logged in, you can change this by going here:

https://myaccount.google.com/lesssecureapps

I assume you have the ssmtp package installed on your system. You need to edit the file called /etc/ssmtp/ssmtp.conf

# The user that gets all the mails  
root=emailaddress@gmail.com  
# The mail server  
mailhub=smtp.gmail.com:587  
# The address where the mail appears to come from for user authentication.  
RewriteDomain=gmail.com  
# The full hostname. You need to use a FQDN or localhost  
Hostname=localhost  
# Use TLS before starting negotiation  
UseTLS=YES  
# Google requires the use of starttls  
UseSTARTTLS=YES  
# Your e-mail address as your username  
AuthUser=emailaddress@gmail.com  
# Your password as your password  
AuthPass=thisisyourpassword  
# Email 'From header's can override the default domain?  
FromLineOverride=YES  
# Your certificate bundle  
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt  


Please verify that your bundle is in that location.

A note on passwords with ssmtp

There has been a bug for many years regarding special characters in ssmtp passwords. Especially with passwords like 123#456, where a pound sign is added, it won't parse this properly towards the server. I personally advice to use longer passwords, like DKDbxnx2fy9zTQEdgxxUqBLm instead. There are several password generators online that can assist you with creating a password like this.

Comments