I needed a quick way to send some files from the command line when logged into a Solaris server via ssh.
This assumes the server is already configured to deliver your smtp mail. I also used mailx for the sending client.
Here is how I did it, for your geeky reference.
First write your message:
cat << EOF > /tmp/mailmsg<br /> Hi this is a message<br /> And this is the second line<br /> EOF
Then populate your recipient list, comma delimited as per the mailx(1) man page:
cat << EOF > /tmp/mailrecipients<br /> firstname.lastname@example.org,email@example.com<br /> EOF
- Then the actual command that will send your mail
. You need to uuencode your binary attachments, and you can send as many as you need.
(cat /tmp/mailmsg ; uuencode /path/to/file.txt file.txt ; uuencode /location/of/otherfile otherfile) | mailx -s 'Subject' -r firstname.lastname@example.org `cat /tmp/mailrecipients`
You need to specify each file name twice, once for source file to encode, and once for the encoded file name; as per the uuencode(1C) man page. If you are sending from some local account on the server, the -r switch allows you to specify an alternate return address for the recipients (in other words your normal email address).
PS: watch for the quotes and backticks. Dont mix them up!
Hope this helps you out someday.