Operating System - HP-UX
1753500 Members
4251 Online
108794 Solutions
New Discussion юеВ

Re: Send email as HTML document

 
SOLVED
Go to solution
Michael Resnick
Advisor

Send email as HTML document

I've got a process that sends an email to certain users when it completes. I'd like to include HTML code in the text, but when the message is sent to the user, the HTML code shows up and is not interpreted by the email reader.

The email client (Outlook 2000) can display HTML-formatted messages.

I'm just sending a file (message.html) using mailx as follows:

cat message.html | mailx -m -s "test" userid

Can anyone help?

Thanks!

mike
8 REPLIES 8
Misa
Frequent Advisor

Re: Send email as HTML document

My first thoughts are "what happens if you leave off the -m" and "have you validated that all the required HTML tags, etc are correct in your source." Can you copy a sample HTML email (as a file) and open with outlook to see how it goes?

But I don't use an HTML-enabled MUA, sorry.

--Misa
Steven Sim Kok Leong
Honored Contributor

Re: Send email as HTML document

Hi,

You need to add the appropriate headers to allow your message to be interpreted as html i.e. add the Content-Type, Content-Transfer-Encoding and MIME-Version:

From: abc@xyz.com
To: def@xyz.com
Subject: This is html
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

...


I integrated an expect script with the sending of html-embedded emails. No problems reading the html from Microsoft Outlook.

Hope this helps. Regards.

Steven Sim Kok Leong
Michael Resnick
Advisor

Re: Send email as HTML document

I've tried with and without the -m option. Neither seems to matter.

The HTML file opens correctly in my browser. I'm testing with a very small file - just a few tags.

I've also tried wrapping some mime encoding around it (see attached), but that doesn't seem to work either - Outlook keeps displaying the entire message as text and seems to ignore the mime stuff.
Steven Sim Kok Leong
Honored Contributor
Solution

Re: Send email as HTML document

Hi,

Being able to open up message.html in a browser does not mean that your mail client can interpret the e-mail body as html.

Have you tried the following in the mail body? This works fine for me.

From: abc@xyz.com
To: def@xyz.com
Subject: This is html
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

...


You can test this by performing a telnet to the mail server's SMTP port:

# telnet mail_server 25
mail from: abc@xyz.com
rcpt to: def@xyz.com
data
From: abc@xyz.com
To: def@xyz.com
Subject: This is html
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

This is a test



.

Hope this helps. Regards.

Steven Sim Kok Leong
Christophe MAILHE
Frequent Advisor

Re: Send email as HTML document

Hi Mike,

You can send HTML in an email using sendmail.

Below some code I am using myself in a few scripts to send HTML messages with a text file attached.

The function is called like :

func_send_mail recipient@xyz.com \path\attachement_file_name

----------------------------

func_send_email()
{

(
echo "From:<$LOGNAME@yourservername.yourcompany.com>"
echo "To:$1"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed;"
echo ' boundary="PAA08673.1018277622/yourservername.yourcompany.com"'
echo "Subject: The file you have requested"
echo ""
echo "This is a MIME-encapsulated message"
echo ""
echo "--PAA08673.1018277622/yourservername.yourcompany.com"
echo "Content-Type: text/html"
echo ""
echo ""
echo "

$2

"
echo "

Please find attcahed the text file you have requested

"
echo "--PAA08673.1018277622/yourservername.yourcompany.com"
echo "Content-Type: text/plain;"
echo " name=\"$2\""
echo "Content-Transfer-Encoding: quoted-printable"
echo "Content-Disposition: attachment;"
echo " filename=\"$2\""
echo ""
cat < $2
echo "--PAA08673.1018277622/yourservername.yourcompany.com"
) | sendmail -t
}

----------------------------

Hope that will help.

Chris.
Steven E. Protter
Exalted Contributor

Re: Send email as HTML document

There is an outlook setting to choose between rtf and html mail.

Tools options mail format

If the user doesn't want html, they'll never see html

Steve
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Harjit Gill
Occasional Advisor

Re: Send email as HTML document

Here is another solution;
Suppose you have a file named 'your_file.html'.
You can do the following:
echo "[include your_file.html text/html base64]" > test_file


elm -s 'Attachment Test' user@system < test_file
Trust Only HP (Higher Power)
Donny Jekels
Respected Contributor

Re: Send email as HTML document

#!/usr/bin/perl -w
require 5.000;

$mail="/usr/lib/sendmail -t";
$temp="/path_of_your_html_file.htm";
$users="emailaddy\@somewhere.tv";
$ccusers="donny\@.jekels.com";
$subject="What you like to spam";
open(MAIL, "| $mail") or die "Can not access $mail $!\n";
open(TEMP, "$temp") or die "Can not open $temp $!\n";
print MAIL "To: $users\n";
print MAIL "Cc: $ccusers\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-Type: text/html;\n";
print MAIL "\tcharset=\"iso-8859-1\"\n";
while () {
print MAIL;
}

close (TEMP);
close (MAIL);



__END__

peace
donny
"Vision, is the art of seeing the invisible"