如何從命令列發送郵件?

如何從命令列發送郵件?

如何從命令列發送郵件?

答案1

  1. 安裝ssmtp 安裝ssmtp

    sudo apt-get install ssmtp
    
  2. 編輯 ssmtp 設定檔:

    gksu gedit /etc/ssmtp/ssmtp.conf
    
  3. 附加以下文字:

    [email protected]
    mailhub=smtp.gmail.com:465
    rewriteDomain=gmail.com
    AuthUser=username
    AuthPass=password
    FromLineOverride=YES
    UseTLS=YES
    
  4. 運行 ssmtp 並提供收件者電子郵件地址:

    ssmtp [email protected]
    
  5. 提供訊息詳細資訊如下:

    To: [email protected]
    From: [email protected]
    Subject: Sent from a terminal!
    
    Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
    (Notice the blank space between the subject and the body.)
    
  6. Ctrl+D發送。


您也可以將文字放入文件中並如下傳送:

ssmtp [email protected] < filename.txt

答案2

大多數時候,您不需要設定 SMTP 伺服器,只需從mail命令列使用即可(如果尚不存在,請使用 進行安裝sudo apt-get install mailutils)。 (或者如果您位於配置了 sendmail 的伺服器上,等等)

marco@dagobah:~$ mail -v [email protected]
Subject: Hello World!
This is an email to myself.

Hope all is well.
.
Cc: 

您可以透過一條.線路終止訊息。此時mail將提示您Cc:輸入訊息(或留空),mail然後列印有關其嘗試執行的操作的附加信息,以及詳細說明連接、傳輸和從郵件伺服器接收資料的處理過程。

答案3

apt-get install sendemail

用法:

sendemail -f [email protected] -t [email protected] -u subject -m "message" -s smtp.gmail.com:587 -o tls=yes -xu [email protected] -xp gmailpassword 

如果您不想在命令列中指定密碼(通常不是一件好事),您可以省略該參數,sendemail 將提示您輸入密碼...並將其顯示在螢幕上,但至少它不會出現在您的命令行歷史記錄中。

答案4

您需要 MTA 來發送郵件。為此,請使用後綴:

sudo apt-get install postfix

發送電子郵件:

echo "test message" | mailx -s 'test subject' [email protected]

幫助

相關內容