lachin
lachin

Reputation: 19

Sending email via gmail acoount in bash

Trying to send email in bash by gmail at first I installed ssmtp then opened configuration file in this path : /etc/ssmtp/ssmtp.conf

Update it to include my Gmail details:

AuthMethod=LOGIN  
Host=smtp.gmail.com  
Port=587  
FromLineOverride=YES  
[email protected]  
AuthPass=my_password  
UseSTARTTLS=YES

using this bash script to send email:

#!/bin/bash  

TO="[email protected]"  
SUBJECT="Subject Here"  
BODY="Body of the email."  

echo "$BODY" | mail -s "$SUBJECT" "$TO"

after running countered with this error :

mail: cannot send message: Process exited with a non-zero status

Trying to troubleshoot, I used this command to test whether simple mailing works or not

 echo "Test email body" | mail -s "Test Subject" [email protected]

and again countered with the same error....

and this is the result of checking mail logs:

tail -f /var/log/mail.log


 sSMTP[710]: Unable to locate mailhub
 sSMTP[710]: Cannot open mailhub:25
 sSMTP[721]: Unable to set Host="smtp.gmail.com"
 sSMTP[721]: Unable to set Port="587"
 sSMTP[721]: Unable to locate mailhub
 sSMTP[721]: Cannot open mailhub:25
 sSMTP[734]: Unable to set Host="smtp.gmail.com"
 sSMTP[734]: Unable to set Port="587"
 sSMTP[734]: Unable to locate mailhub
 sSMTP[734]: Cannot open mailhub:25

geeksforgeeks.org/send-mails-using-a-bash-script

Upvotes: 0

Views: 96

Answers (0)

Related Questions