首页 > 解决方案 > Sendmail bash 脚本读取文本文件并添加超链接

问题描述

下面是我的部分脚本。我可以使用它发送电子邮件,我唯一的问题是当我阅读文本文件(body.txt)时它会忽略新行,因为我的正文电子邮件会发送一大行。

如果我删除

Mime-version:1.0
Content-type:text/html"

比我理解文本文件上的新行。然而这次通过超链接因为纯文本,当我想成为html时。

links=<a href='deleteserid=test@gmail.com'>Unsubscribe</a>

xmail="/usr/sbin/sendmail"

# Fetches subject.txt generated from input.php page.
xsub=$(cat /data3/sss/subject.txt)

# Show from in email.
xfrom="xxx.net"

# Fetches body.txt generated from input.php page.
xmsg=$(cat /data3/ssss/body.txt)
text="$xmsg <br><br> $links"
echo $text
### Compose emails one at a time, per loop.
"$xmail" "$line" << EOF
subject:$xsub
from:$xfrom
Mime-version:1.0
Content-type:text/html
$text
EOF

标签: linuxbashshellsendmail

解决方案


根据

[https://stackoverflow.com/questions/3902455/mail-multipart-alternative-vs-multipart-mixed]

发送 HTML 电子邮件时设置为Content-Typemultipart/alternative


推荐阅读