Sunday, December 24, 2006

Attach a File to Message via Command Line

I'm frequently asked how to attach a file(s) to an email message via the command line. Here's how I do it. By the way, the mail recipient will need to use uudecode.

Here's an example of an email attachment.

# uuencode my_binaryfile1 | mailx -s "Email binary as attachment" esofthub@esofthub.com

For multiple attachments, I use a mail client such as dtmail, Netscape or FireFox. But I've seen this done too.

# uuencode my_binaryfile1 my_binaryfile2 | mailx -s "Email binary as attachment" esofthub@esofthub.com

For NON-binary type files

Please note the ~r (tilde command followed by r)
# mailx esofthub@esofthub.com (hit enter)
Subject: End of Week Status Report (hit enter)
~rendofweekstatus.dat (hit enter)
~. (hit enter)
EOT

The above procedure (non-binary) works great for inline text files.

Also,

# cat endofweekstatus.dat | mailx -s "End of Week Status Report" esofthub@esofthub.com

2 comments:

Anonymous said...

since i could not ftp directly to the server and copy files this helped me.

thanks again

esofthub said...

Interesting comment anon...same thing happened to me a few years back (Korea to California). I ended up splitting and emailing.

Thanks for the comment.