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


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum