简体   繁体   English

使用uuencode和mailx发送电子邮件附件

[英]Sending email attachment using uuencode and mailx

I'm trying to get a system on my home network to send an image (.png) via email. 我正在尝试在家庭网络上安装一个系统,通过电子邮件发送图像(.png)。 The closest I have gotten is this: 我得到的最接近的是:

uuencode -m snapshot.png snapshot.png | mailx -r "sending@myremoteserver.net" -s "Snapshot" -S smtp=smtp.myremoteserver.net me@myremoteserver.net

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. 麻烦的是,我必须通过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). 但是我的邮件客户端没有解码图像文件(我在Thunderbird和各种webmail界面中尝试过,结果相同)。 Is there a better way that actually works? 有没有更好的实际工作方式?

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。

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. 然后你不必担心uuencode东西。 I believe you can add multiple -a options to send multiple attachments as well. 我相信你也可以添加多个-a选项来发送多个附件。

Not sure which version this option appeared though (the servers at my new job don't have it). 不知道这个选项出现在哪个版本(我新工作的服务器没有它)。

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>

I had the same problem and fixed by switch to sendmail, which sends mime types. 我有同样的问题,并通过切换到sendmail修复,sendmail发送mime类型。

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管道。

You just need to get rid the "-m" option. 你只需要摆脱“-m”选项。 It works on Solaris 10 as a sender and outlook/lotus_notes as a mail client. 它适用于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 "sending@myremoteserver.net" -s "Snapshot" -S smtp=smtp.myremoteserver.net me@myremoteserver.net

Hope it helps. 希望能帮助到你。

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. Mimencode旨在替代邮件和新闻使用的uuencode。 The reason is simple: uuencode doesn't work very well in a number of circumstances and ways. 原因很简单:uuencode在许多情况和方式下都不能很好地工作。 In particular, uuencode uses characters that don't translate well across all mail gateways (particularly ASCII <-> EBCDIC gateways). 特别是,uuencode使用的字符在所有邮件网关(特别是ASCII < - > EBCDIC网关)中都不能很好地转换。 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. 此外,uuencode不是标准的 - 有几种变体浮动,以不同和不兼容的方式编码和解码事物,没有基于实现的“标准”。 Finally, uuencode does not generally work well in a pipe, although some variants have been modified to do so. 最后,uuencode在管道中通常不能很好地工作,尽管已经修改了一些变体。 Mimencode implements the encodings which were defined for MIME as uuencode replacements, and should be considerably more robust for email use. Mimencode实现了为MIME定义为uuencode替换的编码,并且对于电子邮件使用应该更加健壮。

uuencode /pth/to/atch.jpg sendasname.jpg | uuencode /pth/to/atch.jpg sendasname.jpg | mailx -s "Subject" mail@mail.com mailx -s“Subject”mail@mail.com

should do fine - use it regularly in solaris. 应该做得很好 - 经常在solaris中使用它。

Leave out the -m switch is all that needs to happen. 省略-m开关是所有需要发生的事情。

怎么样

(uuencode -m snapshot.png snapshot.png) | mailx -r "sending@myremoteserver.net" -s "Snapshot" -S smtp=smtp.myremoteserver.net me@myremoteserver.net

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM