Results 1 to 8 of 8

Thread: Here's one for you ...

  1. #1
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Here's one for you ...

    ... 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.com" richard.peacock@mydomain.com
    but just receive

    in my inbox (MS Outlook with HTML allowed).


    An example of what I am trying to replicate is


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

  2. #2
    Join Date
    Jun 2008
    Location
    Oklahoma, US
    Posts
    822

    Default Re: Here's one for you ...

    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.com" richard.peacock@mydomain.com
    >
    > --------------------
    > but just receive
    > '[image:
    > http://img239.imageshack.us/img239/3...msgpt4.th.jpg]'
    > (http://img239.imageshack.us/my.php?i...textmsgpt4.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/5...msgld9.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

  3. #3
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Re: Here's one for you ...

    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

    Code:
    <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*

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Here's one for you ...

    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.

  5. #5
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Re: Here's one for you ...

    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&#37;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

  6. #6
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Re: Here's one for you ...

    Quote Originally Posted by ken_yap View Post
    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.


    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
    Code:
    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)?

  7. #7
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Re: Here's one for you ...

    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" at least it's *some* progress, so here we go again!!

    FYI yast2 added
    Code:
    relayhost = my.server.ip.address
    into the file /etc/postfix/mail.cf

  8. #8
    Join Date
    Jun 2008
    Location
    /earth/europe/uk/england/west-yorkshire/leeds/mystreet/myhouse
    Posts
    248

    Default Re: Here's one for you ...

    YAY, I THINK I HAVE SUSSED IT!!!!

    Code:
    echo -e "Content-Type: text/html\n<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


    hoorah for badger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •