0

I need to send mail from a linux host with HTML content type and also attach a file to the mail.

cat html_mail.txt

To: me@mydomain.com

Subject: Test Mail

Content-Type: text/html; charset="us-ascii"

Content-Disposition: inline

<span style="background-color:green">This is in green</span>

I tried the below options:

mail: 

mail -a attachment_file < html_mail.txt

"mail" command sends an attachment but the HTML content in html_mail.txt is coming up as plain text in the mail

Execution of the command says "Ignoring headers Content-Type".

sendmail:
cat html_mail.txt |sendmail -t
sendmail sends the html content properly, but I couldn't find an option to send an attachment.
AnFi
  • 10,493
  • 3
  • 23
  • 47

1 Answers1

3

Sending "HTML only" email using low level sendmail command

1) Add necessary MIME headers
(MIME-Version, Content-Type, Content-Transfer-Encoding)

html_mail_file

To: me@mydomain.com
Subject: Test Mail
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7BIT
Content-Disposition: inline

<span style="background-color:green">This is in green</span>

*For non us-ascii charsets declare 8BIT encoding. Most email servers will conduct necessary transformations of "raw" 8BIT encoding.

2) Send it using sendmail program

/usr/bin/sendmail -i -t < html_mail_file

or if you prefer to keep email headers separately

echo | cat email_headers_file - html_file | /usr/bin/sendmail -i -t
AnFi
  • 10,493
  • 3
  • 23
  • 47