[英]Send email with body and attachment with mailx
How do you send an email with both a body and attachment with mailx? 您如何发送带有正文和附件并带有mailx的电子邮件?
This code will send an email with a body: 此代码将发送带有正文的电子邮件:
cat $body | tr -d \\\\r | mailx -s "SUBJECT" foo@bar.com
tr -d \\\\r
is necessary in this case because if the body is not piped through tr
, it will send as a .bin attachment (for this particular body). 在这种情况下, tr -d \\\\r
是必需的,因为如果主体没有通过tr
管道传输,它将作为.bin附件发送(对于此特定主体)。 Found the solution to the body sending as .bin here: Use crontab job send mail, The email text turns to an attached file which named ATT00001.bin 在此处找到了以.bin发送的正文的解决方案: 使用crontab作业发送邮件,电子邮件文本变为名为ATT00001.bin的附件。
I have tried putting -f $attachment
after the subject, but am given the error, More than one file given with -f
, and the command will not run. 我曾尝试将-f $attachment
放在主题后,但得到错误, More than one file given with -f
,该命令将无法运行。
From mailx
's man page : 从mailx
的手册页:
-a file
Attach the given file to the message.
-f
makes mailx process a file as if it was provided on stdin, so you encountered an error because you were providing data to mailx
both through stdin and a file. -f
使mailx像对待stdin上提供的文件一样处理文件,因此您遇到错误,因为同时通过stdin和文件向mailx
提供数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.