Mac OS X,  Mac Security,  Mass Deployment

Mail Attachments from the Command Line

Concurrent with my last post on using mail from the command line there was a thread on the Mac OS X Server email list on using attachments with mail, so I thought I would supplement what they were doing there here (so if you were following that thread the only new thing here are the -c and -b options). Let’s say you have a file on your desktop called orgchart.doc and you wanted to attach it to an email and send it to a few email addresses: contact@org.com, contact2@org.com and krypted@mac.com. We’re also going to bcc secret@org.com.  You would use the following command:

uuencode ~/Desktop/orgchart.doc orgchart.doc | mail -s “orgchart” contact@org.com -c contact2@org.com,krypted@mac.com -b secret@org.com

The uuencode command encodes the attachment. The reason the filename appears twice is that you need to tell it the name of the encoded file. Then we pipe the output into an email using the mail command, attaching the file, using the -s option of the mail command to define a subject and the -c option to define a comma separated list of contacts.  Finally we’re going to bcc secret@org.com by following a -b option with that email address.