How To Send Email from Gmail or SMTP via Linux Command

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 server like Gmail.

Install SendEmail Package

SendEmail SMTP client is available under default Ubuntu repositories, Use following commands to install it.
sudo apt-get update
sudo apt-get install sendemail

Send Email through SMTP

Example 1:-

In this example email body text is passed as argument (-o message-file=/tmp/mailbody.txt) in command.
sendemail -l email.log     \
    -f "sender@domain.com"   \
    -u "Email Subject 1"     \
    -t "receiver@domain.com" \
    -s "smtp.gmail.com:587"  \
    -o tls=yes \
    -xu "youremail@gmail.com" \
    -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 address as well.
cat mailbody.txt | sendemail -l email.log \
    -f "sender@domain.com"  \
    -u "Email Subject 2"  \
    -t "receiver@domain.com"  \
    -cc "receiver2@domain.com"  \
    -bcc "receiver3@domain.com"  \
    -s "smtp.gmail.com:587"  \
    -o tls=yes  \
    -xu "youremail@gmail.com"  \
    -xp "Email Password" 
目前這個方式,您的gmail需要將低安全性應用程式打開。如果可以設定為2階段認證的,您可以使用mutt去發送e-mail,mutt發送在在ubuntu發送信件e-mail的5個方法有介紹。

留言

這個網誌中的熱門文章

【多益】現點現做的英文怎麼說呢?

《Microsoft Word 應用》:圖片被文字蓋住解決方法,不可設定為固定行高

如何在Ubuntu系統上安裝Notepad ++ (Install Notepad++ On Ubuntu 16.04 / 17.10 / 18.04 / 20.04)