简体   繁体   中英

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. 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. 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?

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.

At my old job, the mailx program had an attachment option built in -a .

From 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.

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

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.

mimencode {file} | /usr/sbin/sendmail -t -oi -f {email@domain}

I don't have mimencode in production so I used openssl which seems same:

/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.,

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.

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.

With "-m" it shows "begin-base64 ...", without "-m" it shows the normal attachment.

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

You should use 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.

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

should do fine - use it regularly in solaris.

Leave out the -m switch is all that needs to happen.

怎么样

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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