0

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

My mail doesn't have an -a option... I'm running centOS.
can you use sendmail? Also, I think can use a multi-part mime type to embed a document inside html. Try looking at a raw document that has all the features built in that you need and construct from there. Good luck.
@shellter Can you please give me an example of MIME with sendmail. Thanks.
@Dennis I can't install a 3rd party software, like mutt, on this machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.