We are migrating from one Unix server to another.

Old server
$ uname -a
Linux <redacted> 2.6.9-89.31.1.ELsmp #1 SMP Mon Oct 4 21:53:22 EDT 2010 i686 i686 i386 GNU/Linux
New server
$ uname -a
Linux <redacted> 2.6.32-504.30.3.el6.x86_64 #1 SMP Thu Jul 9 15:20:47 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

When using the below command, mails were sent as HTML content in the old server, but the same command on the new server is only sending plain emails.

  • What are my options here?
  • what can I do to make this work?
My command
$ echo "<b>HTML Message <i>goes</i> here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" -rtest@test.com testr@test.com
  • It look like redhat. Have you checked sendmail's option ? or mail ? mail now know how to attache html (among other) files. – Archemar Nov 4 '15 at 12:50
  • 1
    Looks to me like you have your quotes mixed up (unless I don't know how $(command) works ... try this instead echo "<b>HTML Message <i>goes</i> here</b>" | mail -s "$(echo -e 'This is the subject\nContent-Type: text/html')" -rtest@test.com testr@test.com. By the way, what you are doing is dodgy ... you are relying on terminating the Subject: header and surreptitiously inserting a Content-Type: header into the message - this is something a cracker might want to do and sounds like a good candidate for a bug-fix in the mail program (thus preventing your technique from working). – Murray Jensen Nov 4 '15 at 13:29
  • So what is the proper way then?, I want to send html mails from this new server using 'mail' command, because only that seems to work, sendmail results in a dead.letter – Guest1 Nov 5 '15 at 3:59

The problem is probably that your newer /bin/mail program is adding its own Mime header to the mail, overriding your Content-Type: text/html hack that you have tacked onto the end of the Subject: header.

An easy solution is to bypass mail and simply go straight to sendmail (even if using postfix). Replace your command with:

sendmail -t <<!
From: test@test.com
To: testr@test.com
Subject: This is the subject
MIME-Version: 1.0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<b>HTML Message <i>goes</i> here</b>

If your sendmail doesn't accept -t then remplace that option by the address you are sending to, ie testr@test.com.

  • Thanks but i cant use 'sendmail', it does not work for me.. it just gives a dead.letter. any other options? – Guest1 Nov 5 '15 at 4:01
  • Try replacing the option -t by testr@test.com. Do you know what software package you are using to send mail, e.g. postfix, sendmail? – meuh Nov 5 '15 at 6:27
  • get the same dead.letter, how can I check which software package is installed? – Guest1 Nov 5 '15 at 9:04
  • Assuming you are on an rpm-based OS, do type -p sendmail to find the full path to it, then rpm -qf on that path; eg if the path is /sbin/sendmail, then do rpm -qf /sbin/sendmail. Do the same for mail so we know which mail program you are using too. – meuh Nov 5 '15 at 9:22
  • Thanks, this is what I got for sendmail postfix-2.6.6-6.el6_5.x86_64 sendmail-8.14.4-8.el6.x86_64 and for mail mailx-12.4-8.el6_6.x86_64 – Guest1 Nov 6 '15 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.