Index syndication
comment syndication

Mailing attachments from the Solaris Shell

April 1, 2008 at 18:00 · Filed under unix

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
Hi this is a message
And this is the second line
EOF

Then populate your recipient list, comma delimited as per the mailx(1) man page:

cat << EOF > /tmp/mailrecipients
[email protected],[email protected]
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 [email protected] `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.

    Leave a Comment