In our earlier tutorial we had discussed about SSMTP for sending email through SMTP server via command line. This tutorial makes this process much easier using the sendemail command-line utility. SendEmail is a Lightweight command line SMTP email client for sending emails through the SMTP server.
In this article, we have described how to install sendemail package and a few examples for sending email through remote SMTP servers like Gmail.
Install SendEmail Package
SendEmail SMTP client is available under default Ubuntu repositories, Use the following commands to install it.
sudo apt-get update sudo apt-get install sendemail
Send Email through SMTP
Example 1:
In this example, the email body is passed as an argument (-o message-file=/tmp/mailbody.txt) to the command. Commands read the file content and use at email body content.
sendemail -l email.log \ -f "[email protected]" \ -u "Email Subject 1" \ -t "[email protected]" \ -s "smtp.gmail.com:587" \ -o tls=yes \ -xu "[email protected]" \ -xp "Email Password" \ -o message-file="/tmp/mailbody.txt"
Example 2:
In this example, email body text is passed as piped input from other command output. You can also include cc and bcc email addresses as well.
cat mailbody.txt | sendemail -l email.log \ -f "[email protected]" \ -u "Email Subject 2" \ -t "[email protected]" \ -cc "[email protected]" \ -bcc "[email protected]" \ -s "smtp.gmail.com:587" \ -o tls=yes \ -xu "[email protected]" \ -xp "Email Password"
7 Comments
I dont have 2 factor auth enabled and I am still getting
ERROR => ERROR => SMTP-AUTH: Authentication to smtp.gmail.com:587 failed.
Any ideas ?
Hellow brothers you can teach me how?
sudo apt-get install libio-socket-ssl-perl
sudo apt-get install libnet-ssleay-perl
Works like a charm. Yet I have one question: is there away to pass the body as html? I tried with the -o option referencing to a .html file but it just sends it in clear.
Doesn’t work. Gmail changed the certification routine.
Authentication to smtp.gmail.com:587 failed.
If you have 2 factor auth enabled, you need to create an “application password” in google security, then use that instead of your normal password. it works fine then, as posted here.
Thanks. It worked. You saved my sunday!
Can you tell me where can I configure gmail SMTP? so that i dont have to type every time gmail id and password!