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";)" [email protected] < /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";)" [email protected] < /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?

asked Oct 13, 2014 at 14:07
6
  • Exact duplicate of: unix.stackexchange.com/questions/15405/… Commented Oct 13, 2014 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" [email protected] < /root/test Content-Type: text/html: No such file or directory Commented Oct 14, 2014 at 6: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? Commented Oct 14, 2014 at 7: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" Commented Oct 14, 2014 at 7:14
  • I am using CentOS 6.5 Commented Oct 14, 2014 at 9:15

1 Answer 1

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

answered Oct 14, 2014 at 9:26
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.