使用 mailx 发送带有一个纯文本附件的纯文本正文电子邮件:
(
/usr/bin/uuencode attachfile.txt myattachedfilename.txt;
/usr/bin/echo "Body of text"
) | mailx -s 'Subject' youremail@gmail.com
下面是与上面相同的命令,没有换行符
( /usr/bin/uuencode /home/el/attachfile.txt myattachedfilename.txt; /usr/bin/echo "Body of text" ) | mailx -s 'Subject' youremail@gmail.com
确保您有一个/home/el/attachfile.txt
使用以下内容定义的文件:
<html><body>
Government discriminates against programmers with cruel/unusual 35 year prison
sentences for making the world's information free, while bankers that pilfer
trillions in citizens assets through systematic inflation get the nod and
walk free among us.
</body></html>
如果您没有 uuencode,请阅读以下内容:https ://unix.stackexchange.com/questions/16277/how-do-i-get-uuencode-to-work
在 Linux 上,使用 sendmail 发送带有 PDF 附件的 HTML 正文电子邮件:
确保您已安装 ksh:yum info ksh
确保您已安装和配置 sendmail。
确保您已安装并可用 uuencode:https ://unix.stackexchange.com/questions/16277/how-do-i-get-uuencode-to-work
创建一个名为的新文件test.sh
并将其放在您的主目录中:/home/el
将以下代码放入test.sh
:
#!/usr/bin/ksh
export MAILFROM="el@defiant.com"
export MAILTO="youremail@gmail.com"
export SUBJECT="Test PDF for Email"
export BODY="/home/el/email_body.htm"
export ATTACH="/home/el/pdf-test.pdf"
export MAILPART=`uuidgen` ## Generates Unique ID
export MAILPART_BODY=`uuidgen` ## Generates Unique ID
(
echo "From: $MAILFROM"
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
echo ""
echo "--$MAILPART"
echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
echo ""
echo "--$MAILPART_BODY"
echo "Content-Type: text/plain; charset=ISO-8859-1"
echo "You need to enable HTML option for email"
echo "--$MAILPART_BODY"
echo "Content-Type: text/html; charset=ISO-8859-1"
echo "Content-Disposition: inline"
cat $BODY
echo "--$MAILPART_BODY--"
echo "--$MAILPART"
echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo ""
uuencode $ATTACH $(basename $ATTACH)
echo "--$MAILPART--"
) | /usr/sbin/sendmail $MAILTO
更改顶部的导出变量test.sh
以反映您的地址和文件名。
下载一个测试pdf文档并放入/home/el
名为pdf-test.pdf
创建一个名为 /home/el/email_body.htm 的文件并将这一行放入其中:
<html><body><b>this is some bold text</b></body></html>
确保 pdf 文件有足够的 755 权限。
运行脚本./test.sh
检查您的电子邮件收件箱,文本应为 HTML 格式,并且 pdf 文件会自动解释为二进制文件。请注意不要在一天内使用此功能超过 15 次,即使您将电子邮件发送给自己,gmail 中的垃圾邮件过滤器也会将一个域喷出的电子邮件列入黑名单,而不会让您选择让它们通过。你会发现这不再有效,或者它只允许附件通过,或者电子邮件根本无法通过。如果您必须对此进行大量测试,请将它们分散几天,否则您将被标记为垃圾邮件发送者,此功能将不再起作用。