thedp
thedp

Reputation: 8508

Bash: Sending HTML with an attached file?

I'm looking for a way to send an HTML email from bash with an attached file. I've tried the following line, but it doesn't work 100%. The below line sends an HTML email, but there is no attached file:

( cat body.html ; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "$(echo -e "my subject\nContent-Type: text/html")" [email protected]

If I remove the Content-Type: text/html to indicate this is an HTML email then the attachment works:

( cat body.html ; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "$(echo -e "my subject")" [email protected]

How can I have both?

Thank you

Upvotes: 0

Views: 1998

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 360143

Try this:

( cat body.html; uuencode in-attachfile.txt out-attachfile.txt ) | mail -s "my subject" -a "Content-Type: text/html" [email protected]

You may want to send the attachment using MIME (via mutt, for example). See this for more information.

Upvotes: 2

Related Questions