Here's one for you ...

… is it possible to send a HTML email using mailx?
I have tried

printf "<html><table><tr><td>blah</td></tr></table></html>" | mailx mailx -A mpl -s "TEST EMAIL" -r "nagios.admin@mydomain.com" richard.peacock@mydomain.com

and

echo -e "<html><table width=100%><tr><td>blah</td></tr></table></html>" | mailx mailx -A mpl -s "Host Alert from $HOSTNAME$ - Host is $HOSTSTATE$" -r "nagios.admin@mydomain.com" richard.peacock@mydomain.com

but just receive
http://img239.imageshack.us/img239/3898/plaintextmsgpt4.th.jpg](http://img239.imageshack.us/my.php?image=plaintextmsgpt4.jpg)
in my inbox (MS Outlook with HTML allowed).

An example of what I am trying to replicate is
http://img392.imageshack.us/img392/5051/htmlmsgld9.th.jpg](http://img392.imageshack.us/my.php?image=htmlmsgld9.jpg)

note: i know the HTML required to create the table but not how to get mailx to send it as HTML

badger fruit wrote:

>
> … is it possible to send a HTML email using mailx?
> I have tried
> Code:
> --------------------
> printf “<html><table><tr><td>blah</td></tr></table></html>” | mailx
> mailx -A mpl -s “TEST EMAIL” -r “nagios.admin@mydomain.com
> richard.peacock@mydomain.com
>
> --------------------
> and
> Code:
> --------------------
> echo -e “<html><table width=100%><tr><td>blah</td></tr></table></html>”
> | mailx mailx -A mpl -s “Host Alert from $HOSTNAME$ - Host is
> $HOSTSTATE$” -r “nagios.admin@mydomain.comrichard.peacock@mydomain.com
>
> --------------------
> but just receive
> ‘[image:
> http://img239.imageshack.us/img239/3898/plaintextmsgpt4.th.jpg]’
> (http://img239.imageshack.us/my.php?image=plaintextmsgpt4.jpg)
> in my inbox (MS Outlook with HTML allowed).
>
>
> An example of what I am trying to replicate is
> ‘[image: http://img392.imageshack.us/img392/5051/htmlmsgld9.th.jpg]’
> (http://img392.imageshack.us/my.php?image=htmlmsgld9.jpg)
>
> note: i know the HTML required to create the table but not how to get
> mailx to send it as HTML
>
>
well, mailx mostly makes ‘plain text’ messages.

you CAN make it attach an HTML file by using the -a option, but then again,
that’s not what you’re looking for either.

If you want to send an HTML type email, you almost have to build it yourself
and send it through mailx.

HTML emails have two (or more) sections, a mime-multipart encoded part (the
HTML version) and a plain text part (the plain text version).

Best method might be to email yourself some ‘HTML email’, and have a look at
the source data for it. Then build a script to create the multi-part email
and send it out.

I’ve done it before myself. mailx handles the mime-type of attachments
properly, but really only puts in the plain-text of an email.

(this would be where I grumble about that new-fangled html-email and the evil
inherent…)

Loni

L R Nix
lornix@lornix.com

Hmm, thank you lornix …
So i had a look at a HTML email that I received from someone and

a) was amazed how much CR4P is added if you use outlook to compose your email and
b) there was a “header” in the source code of the message which read


<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

I think this may be the key (or at least the first line) to producing a HTML email … wish me luck as I am going to try it now …

drum roll

If you use mailx to send your “HTML” mail, you will still be missing one critical line that’s not in the body but in the headers, namely:

Content-Type: text/html

You could invoke sendmail directly to send out HTML mail. That way you get control over the headers too. There are libraries in almost any language you prefer to talk to sendmail, which would be easier.

Result - didn’t work (lol)
I opened the email and from the Outlook Tools menu, selected Options; in there there is a box for “internet headers” and in there, i read:-

Microsoft Mail Internet Headers Version 2.0
Received: from uk-lds-nag-01.mydomain.local ([192.168.101.77]) by uk-lds-exch-01.mydomain.local with Microsoft SMTPSVC(6.0.3790.1830);
Wed, 2 Jul 2008 14:06:39 +0100
Date: Wed, 02 Jul 2008 15:46:37 +0100
From: nagios.admin@mydomain.com
To: richard.peacock@mydomain.com
Subject: Test email
Message-ID: <486b94cd.SNEe5qBJOJYnQgmK%nagios.admin@mydomain.com>
User-Agent: Heirloom mailx 12.2 01/07/07
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Return-Path: nagios.admin@mydomain.com
X-OriginalArrivalTime: 02 Jul 2008 13:06:39.0763 (UTC) FILETIME=[774F4630:01C8DC44]

Comparing that to the HTML emails

Microsoft Mail Internet Headers Version 2.0
Received: from spamfilter.mydomain.local ([82.71.160.29]) by uk-lds-exch-01.mydomain.local with Microsoft SMTPSVC(6.0.3790.1830);
Wed, 2 Jul 2008 09:50:42 +0100
Received: from spamfilter.mydomain.local (localhost.localdomain [127.0.0.1])
by localhost (Email Security Appliance) with SMTP id 84534136EC5B
for <recipient@mydomain.com>; Wed, 2 Jul 2008 08:44:02 +0000 (GMT)
Received: from gse-mta-14.emailfiltering.com (gse-mta-14-tx.emailfiltering.com [194.116.198.211])
by spamfilter.mydomain.local (Email Security Appliance) with ESMTP id 63EC5136EC3B
for <recipient@mydomain.com>; Wed, 2 Jul 2008 08:44:02 +0000 (GMT)
Received: from xxx.xxx.xxx.xxx ([xxx.xxx.xxx.xxx])
by gse-mta-14.emailfiltering.com with emfmta (version 3.6.0.3522.0.r-3.2.3-libc2.3.2) vanilla id 1136387404
for recipient@mydomain.com; Wed, 02 Jul 2008 09:51:34 +0100
Received: from xxx.xxx.xxx.xxx ([xxx.xxx.xxx.xxx]) by ukixeex01.theirdomaincouk.local with Microsoft SMTPSVC(6.0.3790.1830);
Wed, 2 Jul 2008 09:51:33 +0100
Date: Wed, 2 Jul 2008 09:51:09 +0100 (GMT Daylight Time)
From: nimbus@theirdomain.co.uk
Subject: NimBUS Message: Alarm from the_server
To: recipient@mydomain.com
MIME-Version: 1.0
Content-Type: TEXT/html; CHARSET=US-ASCII
Return-Path: nimbus@theirdomain.co.uk
Message-ID: <UKIXEEX01DVniSnRMWu00011074@ukixeex01.theirdomaincouk.local>
X-OriginalArrivalTime: 02 Jul 2008 08:51:33.0693 (UTC) FILETIME=[D42E56D0:01C8DC20]
X-Sophos-ESA: [spamfilter.mydomain.local] 2.2.3.1, Antispam-Engine: 2.6.0.321628, Antispam-Data: 2008.7.2.83710

Ken, I was composing my reply and when i clicked save, notice you have posted. Could I trouble you (or anyone else!) for a quick noob intro to sendmail from the command line?

i tried

echo "hello world" | sendmail recipient@mydomain.com

but not received anything (i presume I would need to somewhere edit a config file to say where my mail server is and the sender details (ie display name and email address)?

bah !!!

so after reading pages and pages and pages of man pages, websites and blogs i managed to (although i don’t recall how as my brain is now dribbling out of my nose) work out how to configure sendmail to actually send an email!!!

seems you have to go into Yast2 > Network Services > Mail transfer Agent.

This configures the appropriate file(s) to where your outbound mail server can be found - bish bash bosh I now have emails. Although they’re still in plain-text and are sent from “root@mydomain.com” instead of “nagios.admin@mydomain.com:confused: at least it’s some progress, so here we go again!!

FYI yast2 added

relayhost = my.server.ip.address

into the file /etc/postfix/mail.cf

YAY, I THINK I HAVE SUSSED IT!!!

echo -e "Content-Type: text/html
<html><body><font color=red>Hello world<hr size=0></font></body></html>" | sendmail -t richard.peacock@mydomain.com

produced a nice HTML email as per screenshot
http://img78.imageshack.us/img78/5338/htmlfromsendmailrp5.th.jpg](http://img78.imageshack.us/my.php?image=htmlfromsendmailrp5.jpg)

hoorah for badger :smiley: