What is the easiest - and preferably most portable - command I can use to email a single file as an attachment a *nix shell?
|
Assuming it's a binary attachment: uuencode [filename] [filename] | mail -s [subject] [recipient address] You don't need to bother with the UUencoding if it's just a text file, eg: mail -s [subject] [recipient address] < [filename] Most *NIXes have mail and uuencode, so this should work pretty much anywhere. |
|||||||||
|
|
Using mutt, you can:
Or, if you don't want to type a body:
|
|||||
|
|
"sendEmail is a lightweight, command line SMTP email client. If you have the need to send email from a command line, this free program is perfect: simple to use and feature rich. It was designed to be used in bash scripts, batch files, Perl programs and web sites, but is quite adaptable and will likely meet your requirements. SendEmail is written in Perl and is unique in that it requires NO MODULES. It has an intuitive and flexible set of command-line options, making it very easy to learn and use. [Supported Platforms: Linux, BSD, OS X, Windows 98, Windows NT, Windows 2000, & Windows XP]" I've used it before and really liked it. You can attach files with the -a option. |
|||||
|
|
I can't add a comment, but..
|
|||
|
|
If you want absolute portability you can telnet into your mail server on port 25 and issue SMTP commands directly. They're not too hard, and it should be very scriptable. |
|||||
|
|
A quick Google turned up this page, which describes a variety of ways to attach files using a variety of applications. A couple of the more prevalent ones --
Additionally, it has links to a couple of shell scripts and a Perl script to craft and send the message, which will probably be more to your liking. |
|||
|
|
|
Some years ago, I wrote a shell script which did just that. It was called binmail.sh. It used a base64 encoder (many source codes can be found with google) and built attachments according to RFC1521. |
|||
|
|
|
Or if you have python available, it'll take only few lines, such as listed here: Sending attachments in python |
|||
|
|
|
||||