≡ 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.in

See also

Share this tutorial on:
{ 0 comments… add one }
Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , , , , , , , , ,