KSH Send Email Attachments Using a Scripts

by on November 19, 2007 · 0 comments· LAST UPDATED November 19, 2009

in , ,

How do I send an email attachment via KSH shell script under UNIX operating systems?

You need to use uuencode and uudecode command encode a binary file, or decode its representation. Use the following syntax to uuencodes file.zip and mails it to a user on another system.

uuencode input output | mail user@example.com
uuencode filename.zip filename.zip | mail -s  'Subject' user@example.com
uuencode filename.tar.gz filename.tar.gz | sendmail recipient(s)
uuencode image.png image.png | mail -s 'Subject' user@example.com
# Send message stored in emailbody.txt and party.jpeg as an attachment
 (cat emailbody.txt; uuencode party.jpeg party.jpeg) | mail -s "Subject" user@example.com

The following example packages up a data directory, compresses it, uuencodes it and mails it to a user:

tar cf - data | compress | uuencode data-dir.tar.Z | mail -s 'Data' vivek@gite.i

See also

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: