≡ Menu

KSH Send Email Attachments Using a Scripts

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

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 0 comments… add one }

Leave a Comment