簡體   English   中英

如何使用 bash 命令“sendmail”發送 html 電子郵件?

[英]How to send a html email with the bash command "sendmail"?

任何人都有可用的演示?

Sendmail 據說不可擴展,但它是免費的,所以我決定暫時先用它:)

以下工作:

(
echo "From: ${from}";
echo "To: ${to}";
echo "Subject: ${subject}";
echo "Content-Type: text/html";
echo "MIME-Version: 1.0";
echo "";
echo "${message}";
) | sendmail -t

有關與sendmail兼容的msmtp故障排除,請參閱:

如果我理解正確,您想使用 linux sendmail 命令以 HTML 格式發送郵件。 此代碼適用於 Unix。 請試一試。

echo "From: me@xyz.com
To: them@xyz.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary='PAA08673.1018277622/server.xyz.com'
Subject: Test HTML e-mail.

This is a MIME-encapsulated message

--PAA08673.1018277622/server.xyz.com
Content-Type: text/html

<html> 
<head>
<title>HTML E-mail</title>
</head>
<body>
<a href='http://www.google.com'>Click Here</a>
</body>
</html>
--PAA08673.1018277622/server.xyz.com
" | sendmail -t

有關sendmail 配置的詳細信息,請參閱此鏈接 希望這可以幫助。

我知道您要求使用 sendmail 但為什么不使用默認郵件 它可以輕松發送 html 電子郵件。

適用於:RHEL 5.10/6.x 和 CentOS 5.8

例子:

cat ~/campaigns/release-status.html | mail -s "$(echo -e "Release Status [Green]\nContent-Type: text/html")" to.address@company.com -v

代碼共享: http : //www.codeshare.io/8udx5

此頁面應該有所幫助 - http://www.zedwood.com/article/103/bash-send-mail-with-an-attachment

它包含一個腳本,用於發送帶有 MIME 附件的電子郵件,即包含 HTML 頁面和圖像。

-一個選項?

參見手冊頁:

-a file
          Attach the given file to the message.

結果:

Content-Type: text/html: No such file or directory

http://senthilkl.blogspot.lu/2012/11/how-to-send-html-emails-using-sendemail.html 中找到解決方案

sendEmail -f "oracle@server" -t "name@domain.com" -u "Alert: Backup complete" -o message-content-type=html -o message-file=$LOG_FILE  -a $LOG_FILE_ATTACH 

要使用mail跟進上一個答案:

通常一個人的 html 輸出是由客戶端郵件程序解釋的,它可能不會使用固定寬度的字體來格式化內容。 因此,您格式良好的 ascii 對齊方式變得一團糟。 要按照上帝的意願發送老式的固定寬度,請嘗試以下操作:

{ echo -e "<pre>"
echo "Descriptive text here."
shell_command_1_here
another_shell_command
cat <<EOF

This is the ending text.
</pre><br>
</div>
EOF
} | mail -s "$(echo -e 'Your subject.\nContent-Type: text/html')" to.address@company.com

您不一定需要“此處的描述性文本”。 行,但我發現有時第一行可能會導致郵件程序以您不希望的方式解釋文件的其余部分,具體取決於其內容。 首先嘗試使用簡單描述性文本的腳本,然后再以您想要的方式微調輸出。

使用更簡單, -a 選項:

cat ~/campaigns/release-status.html | mail -s "Release Status [Green]" -a "Content-Type: text/html" to.address@company.com

暫無
暫無

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

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