Linux 使用带有附件和主题行的 unix 命令发送邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16151470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
send a mail using unix command with attachment and subject line
提问by yatici
I am trying to send a mail with attachment and a subject line using unix's mail command but I get an error if I have both. If I only have a subject line it works, if I only have a attachment it works but not both. Anyone know how to do this?
我正在尝试使用 unix 的邮件命令发送带有附件和主题行的邮件,但是如果我同时拥有这两个命令,则会出现错误。如果我只有一个主题行它可以工作,如果我只有一个附件它可以工作但不能同时工作。有人知道怎么做吗?
data.out | mail -s "DATA" [email protected] < text.out
So this results in "Ambiguous input redirect"
所以这会导致“模糊输入重定向”
采纳答案by ilomambo
According to this articleyou can do what you want as:
根据这篇文章,你可以做你想做的事:
(cat text.out; uuencode data.out data.out) | mail -s "DATA" [email protected]
回答by Petesh
You're asking to send input from the data.out
command into the mail
command, as well as asking it to read from the file text.out
; which is, to say the least ambiguous as the shell cannot do both.
您要求将data.out
命令中的输入发送到mail
命令中,并要求它从文件中读取text.out
;也就是说,至少可以说是模棱两可,因为 shell 不能两者兼而有之。
If you want to get both the text and data into the mail message, then the easiest way to accomplish this is to do something like:
如果要将文本和数据都放入邮件消息中,那么最简单的方法是执行以下操作:
(cat text.out; data.out) | mail -s "DATA" [email protected]
now if data.out
is a file rather than a command, then you can just do:
现在如果data.out
是文件而不是命令,那么您可以执行以下操作:
cat text.out data.out | mail -s "DATA" [email protected]
回答by Ed Plese
If it is available mutt
works well for this as well as it directly supports attachments. I've found the mail
program on some systems does not properly perform MIME encoding even if the attachment is piped in after being passed through uuencode
.
如果它可用,则适用mutt
于此,并且它直接支持附件。我发现mail
某些系统上的程序无法正确执行 MIME 编码,即使附件在通过uuencode
.
An example of using mutt
is:
使用的一个例子mutt
是:
echo "body text" | mutt -a attachment.txt -s "subject text" -- [email protected]