Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert html tags from withing C++ function

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I am working on a project in which I need to insert an html tag (<a href>) into all the incoming messages.
The mail client(Exim) hands over the incoming message to my program and I insert the html tag at the appropriate place.
The code I am using to achieve this is
Code:
string insrtstring = "Report as <a href=[URL unfurl="true"]http://users."[/URL] + pdObj.m_hostDomain1 +"/spamreporting.php?ms="+pdObj.m_filename +"&disp=allow&movedir="+name+">SPAM</a>"; => string to be inserted.

pdObj.InsertLine(allowEmail, choice, insrtstring, fnemail); =>function which actually inserts the string inside the message.
The string is inserted at the desired location in the message however it is not html formatted, the whole string is inserted as is, without any html formatting, like <a href =
Appreciate any help.
Thanks,
Tewari
 
Is the E-mail plain text or HTML?
It could be a problem with the location where InsertLine() puts the HTML tag.

HTML E-mail messages have 2 parts, an HTML part and a plain text part.
 
Could be both plain text or html.
The InsertLine() function puts the HTML tag either at the top after the headers or at the bottom after the message body.

 
OK, I'm a little confused. HTML tags won't do any good if you have a plain text E-mail.
Here is an example of a plain text E-mail created by Outlook Express:
Code:
From: "Joe Blow" <a@b.com>
To: "a@b.com"
Subject: This is the subject
Date: Tue, 7 Mar 2006 23:22:49 -0500
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527

This is the body

And here is the same E-mail as an HTML E-mail:
Code:
From: "Joe Blow" <a@b.com>
To: "a@b.com"
Subject: This is the subject
Date: Tue, 7 Mar 2006 23:16:25 -0500
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_000B_01C6423D.3139FD00"
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C6423D.3139FD00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is the body
------=_NextPart_000_000B_01C6423D.3139FD00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is the =
body</FONT></DIV></BODY></HTML>

------=_NextPart_000_000B_01C6423D.3139FD00--
Are you saying the function inserts the text between the
Code:
Content-Transfer-Encoding: quoted-printable
and
Code:
------=_NextPart_000_000B_01C6423D.3139FD00
lines?
 
Yes, I have options set which indicate where to insert the line, option 1 is to insert the line after the headers and before the message body starts and
option 2 is inserting the line at the end of the message.

I was thinking is there a way that we could modify the headers so that the
Code:
Content-Type: text/plain
line in the headers be modified to
Code:
Content-Type: text/html
, which is the content type defined when the message contains html formatting.
 
If it's a plain text message, you won't even have a "Content-Type: text/plain" header. If it's an HTML message and you change it from "text/plain" to "text/html", you'll have two HTML sections with the same body (but one with no HTML tag formatting).

If your function (option 2) inserts the link like this:
Code:
From: "Joe Blow" <a@b.com>
To: "a@b.com"
Subject: This is the subject
Date: Tue, 7 Mar 2006 23:16:25 -0500
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----=_NextPart_000_000B_01C6423D.3139FD00"
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01C6423D.3139FD00
Content-Type: text/plain;
    charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

This is the body
------=_NextPart_000_000B_01C6423D.3139FD00
Content-Type: text/html;
    charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>This is the =
body</FONT></DIV></BODY></HTML>
[b]<a href =[URL unfurl="true"]http://tek-tips.com>Tek-tips</a>[/URL][/b]
------=_NextPart_000_000B_01C6423D.3139FD00--
Then the link shows up in Outlook Express. Although since it's outside the <html></html> tags, I don't know if other E-mail clients might have problems parsing it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top