0

I was trying to send an html file using mail commnad, but the mail contents alignment is not working.

Here is the command used to send the mail

/bin/mail -s "$(echo -e "log - $date\nFrom: ABC \n";)" abc@gmail.com < /root/test

After searching, I found that we need to add "Content-Type" on the header. So I have added it on the header and its worked, but the From header is not working and some additional info showing on the mail.

Here is the command I used to send mail :

/bin/mail -s "$(echo -e "log - $datet\nContent-Type: text/html\nFrom: ABC \n";)" abc@gmail.com < /root/test

The additional info showing on the mail while adding content-type is as follows : From: ABC User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable = =20

Could anyone please tell me how to send html using mail command with all the above options?

itzforu
  • 115
  • 4
  • 15
  • Exact duplicate of: http://unix.stackexchange.com/questions/15405/how-do-i-send-html-email-using-linux-mail-command – Aaron Digulla Oct 13 '14 at 14:12
  • Thanks for your reply. I already saw this post. I have tried with mailx command too, but was getting content-type error : mailx -a 'Content-Type: text/html' -s "Subject" abc@gmail.com < /root/test Content-Type: text/html: No such file or directory – itzforu Oct 14 '14 at 06:49
  • The error indicates that your version of `mailx` treats `-a` as an attachment instead of an additional header. Which OS and which version of mailx? – Aaron Digulla Oct 14 '14 at 07:10
  • Update: The first answer in the linked question says clearly that there is more than one version of `mailx` and you need the one "from mailutils on Ubuntu or Debian's bsd-mailx" – Aaron Digulla Oct 14 '14 at 07:14
  • I am using CentOS 6.5 – itzforu Oct 14 '14 at 09:15
  • Get the sources for `mailutils` from http://mailutils.org/ and compile it yourself. – Aaron Digulla Oct 14 '14 at 09:18

1 Answers1

0

Use mutt instead. See this question: Send Html page As Email using "mutt"

This question how do what you want but you need a version of mail which supports adding headers: https://unix.stackexchange.com/questions/15405/how-do-i-send-html-email-using-linux-mail-command

If your Linux distro doesn't come with one, then download the sources for mailutils from http://mailutils.org/ and compile them. See this question: https://superuser.com/questions/243152/how-to-send-email-message-content-as-html-rather-than-plain-text

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820