Here is how I send emails from the command line in Ubuntu servers in the cloud via G SUote connect emails
If you use ufw for your Ubuntu firewall then allow port 587 out traffic (read more in securing Ubuntu in the cloud here).
sudo ufw allow out 587
Ensure your port is open on IPV4 and IPV6.
sudo ufw status
If you have a GUI managed firewall with your server host then configure it to allow port 587 (out).
Read more on useful terminal commands here or setting up a Digital Ocean Ubuntu server here for as low as $5 a month here, Vultr server for as low as $2.5 here ($10 free credit). Read more about setting up an AWS Ubuntu server here.
Install sendmail and other pre requisites
apt-get install libio-socket-ssl-perl libnet-ssleay-perl sendemail
Send an email from the command line
sendemail -f email@example.com -t firstname.lastname@example.org -u "test email" -m "test message" -s smtp.gmail.com:587 -o tls=yes -xu email@example.com -xp y@ursecurepa$$wordg@eshere123
This is not a drop-in replacement for Outlook or Thunderbird email clients but it is perfect for command line alerts to con-jobs or start-up notifications.
Sending an email with an attachment
sendemail -f firstname.lastname@example.org -t email@example.com -u "test email" -m "test message" -s smtp.gmail.com:587 -o tls=yes -xu firstname.lastname@example.org -xp Y@urSecu&rpa$$w@rd123 -a /folder/file.zip
Coming soon: A guide on backing up Ubuntu with Rsync etc.
Donate and make this blog better
Ask a question or recommend an article
v1.1 added links to two G Suite guides.