How to attach a file to an email using the Linux mail command

How to attach a binary…

Login

Blog History

How to attach a binary file to an email using the Linux mail command:

( cat bodyofmail.txt; uuencode filetoattach attachmentnameinemail ) |\ 
mail -s "The subject" [email protected] 
# for example 
# if I had the text body of my email in "body.txt" 
# and I had a PDF file named "mypdf.pdf" which 
# I wanted it sent as an attachment with the same name 
# I would use this command: 
( cat body.txt; uuencode mypdf.pdf mypdf.pdf ) |\ 
mail -s "Attached is your Invoice" [email protected] 
# you can also stuff you email BODY into a variable 
# BODY="This is the body\n\nThere are a lot of things to do with mail\n" 
# use the -e option to get echo to translate the embedded new lines 
# (e.g. \n) 
( echo -e $BODY; uuencode mypdf.pdf mypdf.pdf ) |\ 
mail -s "Attached is your Invoice" [email protected]

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.