Easiest way to email file via command line in *nix?
What is the easiest - and preferably most portable - command I can use to email a single file as an attachment a *nix shell?
Solution 1:
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.
Solution 2:
Using mutt, you can:
mutt -z -a <file> -s <subject> -- [email protected]
Or, if you don't want to type a body:
mutt -z -a <file> -s <subject> -- [email protected] < /dev/null
Solution 3:
"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.
Solution 4:
I can't add a comment, but..
- The answers to this are going to depend very much upon which, if any, derivative of
mailx
you have available. - Although the file should be displayed without any problems by the receiving MUA, piping from
uuencode
won't technically produce an email with an attachment. Take a look at the source of the email you receive to see why.
Solution 5:
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.