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.

ADVERTISEMENTS

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 SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.