使用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中的垃圾邮件过滤器会将黑名单中涌出的电子邮件列入黑名单,而没有让您选择允许它们通过的功能。而且您会发现它不再起作用,或者只能通过附件,或者根本无法通过电子邮件。如果您必须对此进行大量测试,请将其分散几天,否则您将被标记为垃圾邮件发送者,此功能将不再起作用。