bash 使用 uuencode 和 mailx 发送电子邮件附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20862213/
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
Sending email attachment using uuencode and mailx
提问by user2646340
I'm trying to get a system on my home network to send an image (.png) via email. The closest I have gotten is this:
我正在尝试让我的家庭网络上的系统通过电子邮件发送图像 (.png)。我得到的最接近的是这个:
uuencode -m snapshot.png snapshot.png | mailx -r "[email protected]" -s "Snapshot" -S smtp=smtp.myremoteserver.net [email protected]
Which gets the mail to me, but the output leaves a bit to be desired...
这将邮件发送给我,但输出有点不尽人意......
begin-base64 755 snapshot.png
AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8A
AAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA
AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA
(well, you get the idea...)
AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8A
AAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAA
AP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/
====
The trouble is, I HAVE to send through smtp.myremoteserver.net. But the image file isn't getting decoded by my mail client (I've tried in Thunderbird and in various webmail interfaces, same result). Is there a better way that actually works?
问题是,我必须通过 smtp.myremoteserver.net 发送。但是图像文件没有被我的邮件客户端解码(我已经在 Thunderbird 和各种网络邮件界面中尝试过,结果相同)。有没有更好的实际工作方法?
Update: Just for the fun of it, I ran this:
更新:只是为了好玩,我运行了这个:
uuencode -m snapshot.png snapshot.png > coded.txt
And upon decoding it, I got a scrambled, unviewable mess. So the problem must be with the uuencoding.
解码后,我得到了一个乱七八糟的、看不见的烂摊子。所以问题一定出在uuencoding上。
回答by jas_raj_total
At my old job, the mailx
program had an attachment option built in -a
.
在我以前的工作中,该mailx
程序内置了一个附件选项-a
。
From http://linux.die.net/man/1/mailx:
来自http://linux.die.net/man/1/mailx:
-a file
Attach the given file to the message.
-一份文件
将给定的文件附加到消息中。
Then you don't have to worry about the uuencode
stuff. I believe you can add multiple -a
options to send multiple attachments as well.
那么你就不必担心这些uuencode
东西了。我相信您也可以添加多个-a
选项来发送多个附件。
Not sure which version this option appeared though (the servers at my new job don't have it).
不确定这个选项出现在哪个版本(我新工作的服务器没有它)。
回答by Arun Murthy
On ubuntu, I was able to successfully send mail with attachment using
在 ubuntu 上,我能够成功地使用附件发送邮件
uuncode input_file1.jpg attachment1.jpg >tempfile
uuncode input_file2.jpg attachment2.jpg >>tempfile
cat tempfile | mailx -s "subject" <email>
回答by Aimin Pan
I had the same problem and fixed by switch to sendmail, which sends mime types.
我遇到了同样的问题,并通过切换到发送 mime 类型的 sendmail 来修复。
mimencode {file} | /usr/sbin/sendmail -t -oi -f {email@domain}
I don't have mimencode in production so I used openssl which seems same:
我在生产中没有 mimencode 所以我使用了 openssl ,它看起来是一样的:
/usr/bin/openssl base64 -e < {file} | /usr/sbin/sendmail -t -oi -f {email@domain}
If you have more recipients, or subject, you can input at the beginning of the pipe, and append mimencode output at the end, eg.,
如果您有更多的收件人或主题,您可以在管道的开头输入,并在末尾附加 mimencode 输出,例如,
To: {email1} {email2}
Cc: {email3}
Subject: some subject
Mime-Version:1.0
Content-Type: text/plain
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename={filename}
{mimencode output here}
You can output all these to a file and then cat to the sendmail pipe.
您可以将所有这些输出到一个文件,然后将 cat 输出到 sendmail 管道。
回答by omichaud
uuencode /pth/to/atch.jpg sendasname.jpg | mailx -s "Subject" [email protected]
uuencode /pth/to/atch.jpg sendasname.jpg | mailx -s "主题" [email protected]
should do fine - use it regularly in solaris.
应该没问题 - 在 solaris 中定期使用它。
Leave out the -m switch is all that needs to happen.
省略 -m 开关是所有需要发生的事情。
回答by Aimin Pan
Read this: https://support.microsoft.com/en-us/kb/2590107
阅读:https: //support.microsoft.com/en-us/kb/2590107
You should use mimencode.
您应该使用 mimencode。
Mimencode is intended to be a replacement for uuencode for mail and news use. The reason is simple: uuencode doesn't work very well in a number of circumstances and ways. In particular, uuencode uses characters that don't translate well across all mail gateways (particularly ASCII <-> EBCDIC gateways). Also, uuencode is not standard -- there are several variants floating around, encoding and decoding things in different and incompatible ways, with no "standard" on which to base an implementation. Finally, uuencode does not generally work well in a pipe, although some variants have been modified to do so. Mimencode implements the encodings which were defined for MIME as uuencode replacements, and should be considerably more robust for email use.
Mimencode 旨在替代 uuencode 用于邮件和新闻用途。原因很简单:uuencode 在许多情况和方式下都不能很好地工作。特别是,uuencode 使用的字符在所有邮件网关(尤其是 ASCII <-> EBCDIC 网关)中都不能很好地转换。此外,uuencode 不是标准的——有几种变体在浮动,以不同且不兼容的方式编码和解码事物,没有“标准”作为实现的基础。最后, uuencode 在管道中通常不能很好地工作,尽管已经修改了一些变体来这样做。Mimencode 实现了为 MIME 定义的编码作为 uuencode 替换,并且对于电子邮件使用应该更加健壮。
回答by user312987
You just need to get rid the "-m" option. It works on Solaris 10 as a sender and outlook/lotus_notes as a mail client.
你只需要去掉“-m”选项。它在 Solaris 10 上作为发件人工作,在 Outlook/lotus_notes 上作为邮件客户端工作。
With "-m" it shows "begin-base64 ...", without "-m" it shows the normal attachment.
使用“-m”显示“begin-base64 ...”,不使用“-m”显示正常附件。
Try:
尝试:
uuencode snapshot.png snapshot.png | mailx -r "[email protected]" -s "Snapshot" -S smtp=smtp.myremoteserver.net [email protected]
Hope it helps.
希望能帮助到你。
回答by michael501
how about
怎么样
(uuencode -m snapshot.png snapshot.png) | mailx -r "[email protected]" -s "Snapshot" -S smtp=smtp.myremoteserver.net [email protected]