簡體   English   中英

如何在Linux中使用sendmail命令發送電子郵件

[英]How to send an email using sendmail command in linux

我嘗試了以下兩個命令。 1)發件人:mail_id收件人:Recepient_mail_id您好,這是我的郵件,我正在將其發送給您! 2)回顯“我的消息” | sendmail -s主題Receipient_mail_id

但是沒有收到任何收件人的郵件地址的郵件。

SMTP服務器已安裝在另一台服務器上,並且已啟動並正在運行。 因此,有人可以幫助我解決如何使用sendmail或smtp命令通過該SMTP服務器發送測試電子郵件嗎?

1.使用sendmail命令:

創建一個包含電子郵件內容的文件:

$ cat /tem/email.txt

主題:終端電子郵件發送

電子郵件內容行1

電子郵件內容行2

現在,使用以下命令發送電子郵件:

$ sendmail user@example.com </tem/email.txt

2.使用“郵件”命令:

$ mail -s“測試主題” user@example.com </ dev / null

另外,您可以使用此命令發送附件。 使用-a表示mailx,使用-A表示mailutils。

$ mail -a /opt/file.sql -s“備份文件” user@example.com </ dev / null

另外,我們可以添加逗號分隔的電子郵件,以將電子郵件一起發送給多個收件人。

$ mail -s“測試電子郵件” user @ example.com,user2 @ example.com </ dev / null

3.使用“ mutt”命令:

$ mutt -s“測試電子郵件” user@example.com </ dev / null

發送包含附件的電子郵件

$ mutt -s“測試電子郵件” -a /opt/backup.sql user@example.com </ dev / null

sendmail希望電子郵件采用“原始”格式。 通常,最好使用更高級別的命令,例如mail

您可以嘗試以下shell腳本

#!/bin/sh

# sendmail command line optons:
# -i - do not treat lines starting with dot specially
# -t - read recipients lists from message headers: TO,CC,BCC
# -v - use verbose mode (describe what is happening) 

/usr/sbin/sendmail -i -t << MESSAGE_END
From: mail_id 
To: Recepient_mail_id 

Hi, this is my message, 
and I'm sending it to you! 
MESSAGE_END

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM