Can't send email from a bash script

-1

0

#!/bin/bash
SMTPTO=akshaysingh@gmail.com
SMTPFROM=akshaysingh1@gmail.com
SMTPSERVER=smtp.googlemail.com:587
SMTPUSER=akshaysingh
SMTPPASS=password
MESSAGE="123"
SUBJECT="THIS IS END."
sendemail -f $SMTPFROM -t $SMTPTO -u $SUBJECT -m $MESSAGE -s $SMTPSERVER -xu $SMTPUSER -xp $SMTPPASS -o tls=yes

It's giving the error:

sendemail[3854]: ERROR => Connection attempt to smtp.googlemail.com:587 failed: IO::Socket::INET6: connect: Connection refused

akshay singh

Posted 2015-09-08T19:39:36.723

Reputation: 1

i also install sendEmail pckage – akshay singh – 2015-09-08T19:41:47.700

"If you tried configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL). " – DavidPostill – 2015-09-08T19:46:20.923

Problems sending mail with POP or IMAP – DavidPostill – 2015-09-08T19:47:55.897

1

Doesn't smtp.googlemail.com need a complete e-mail address as username? So SMTPUSER=akshaysingh@gmail.com or something? And did you set the "Allow less secure apps access" to ON in https://myaccount.google.com/security (all the way at the bottom of that page) or at https://www.google.com/settings/security/lesssecureapps directly? (Don't forget to set it back if it doesn't help)

– Rik – 2015-09-08T19:47:58.587

Answers

1

You have your SMTP server set to:

SMTPSERVER=smtp.googlemail.com:587

But according to the official Google documentation on SMTP setup, the FQDN of SMTP Service should be smtp.gmail.com. So perhaps change that to:

SMTPSERVER=smtp.gmail.com:587

Additionally, your SMTP user is this:

SMTPUSER=akshaysingh

But Google documentation clearly states it should be the full [username]@gmail.com address:

Your full Gmail or Google Apps email address required for authentication

So perhaps change that to:

SMTPUSER=akshaysingh@gmail.com

JakeGould

Posted 2015-09-08T19:39:36.723

Reputation: 38 217

i also tried but it tells same error and also re update send email package – akshay singh – 2015-09-08T19:58:34.650