Problem with HTML special characters automatic replacement - & becomes&

A

Arnaud

Hello,

I'm using a script in Access to send an email using Outlook. I'm using a
file to store my HTML email template.

My script is smthing like :
Set myOutlook = New Outlook.Application
Set myEmail = myOutlook.CreateItem(olMailItem)
myEmail.To = Recordset.email
myEmail.BodyFormat = olFormatHTML
myEmail.HTMLBody = myEmailTemplate
myEmail.Display

Everything works fine except automatic transformation of the &
character, which is a special character in HTML.

My template includes an HTML link in the form :
http://mydomain.com?param1=value1&param2=value2. Outlook transforms the
& character in the url by the & sequence
(http://mydomain.com?param1=value1&param2=value2), and therefore my
link is no longer working.

Have someone an idea on how to be sure that the & character won't be
modified ??

I made a few experiments and found that &, <, >, special characters are
transformed whereas ©, ® ~, ", «, », à, â, ä, æ, è, ê are not... why
such a difference of treatment ??

My configuration :
MS Outlook 2002 - SP2
MS Access 2002 - SP2
Microsoft Visual Basic 6.3

PS : I searched the forum and found nothing valuable - found one email
about the same problem
(http://groups.google.fr/groups?hl=f...icrosoft.public.outlook.program_vba&scoring=d)
but without any response.

Best regards and thanks in advance for any response,
Arnaud
 
A

Arnaud

Hello again,

Has anybody a clue about the problem I'm facing ?

Maybe the mail is not clear enough (I'm not english native...), so let
me know if that is the case.

Best regards,
Arnaud

Arnaud a écrit:
 
S

Sue Mosher [MVP]

How are you reading in myEmailTemplate? What is the exact HTML tag for that
link in the template? That would be helpful in trying to reproduce the
problem and come up with a solution.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
A

Arnaud

Hello,
1) the way I read the email template - here is the code I use :
~~~~~~~~~~~~~~
Dim applicationPath As String
Dim myEmailTemplate As String
Dim myContactId As String
Dim myOutlook As Outlook.Application
Dim myEmail As Outlook.MailItem

' Check the contact has an email
If IsNull(Recordset.email) Then
MsgBox "This contact has no email."
Exit Sub
End If

' Read the emailTtemplate that is stored in file template.html
applicationPath = Application.CurrentProject.Path
Set fs = New FileSystemObject
Set f = fs.OpenTextFile(applicationPath & "\template.html", 1)
myEmailTemplate = f.ReadAll
f.Close

' Read contact Id
myContactId = Recordset.ContactId
myContactId = Replace(myContactId, "{guid {", "{")
myContactId = Replace(myContactId, "}}", "}")

' Create a new email in Outlook using the template
Set myOutlook = New Outlook.Application
Set myEmail = myOutlook.CreateItem(olMailItem)
myEmail.To = Recordset.email
myEmail.BodyFormat = olFormatHTML
myEmail.Attachments.Add applicationPath & "\logo.gif"
myEmail.Attachments.Add applicationPath & "\background.gif"
myEmail.HTMLBody = myEmailTemplate
myEmail.Display
~~~~~~~~~~~~~~

2) sample of the template used and the html tag that causes pb.
~~~~~~~~~~~~~~
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<STYLE TYPE="text/css">
body {width:100%; height:100%; margin-top:10px; margin-bottom:10px;
margin-left:10px; margin-right:10px;}
..centercolumn {width:570px; margin-top:0px; margin-bottom:0px;
margin-left:0px; margin-right:0px; padding: 10px 10px 10px 10px;
font-family:Arial, sans-serif; font-size:.8em;
font-weight:normal;text-align:center; border-top:1px solid #666666;
border-bottom:1px solid #666666; border-right:1px solid #666666;
border-left:1px solid #666666;}
..footer {width:570px; margin-top:5px; margin-bottom:0px;
margin-left:0px; margin-right:0px; padding: 10px 10px 10px 10px;
background:#ffffff; font-family:"Arial Narrow", Sans-Serif;
font-size:.6em; color:#666666;text-decoration: none;}
..footerLink {text-decoration:none; color:#666666;}
a{text-decoration:none; color:#FF6600;}
a:hover {text-decoration:underline;}
</STYLE>
<title>my Email Template</title>
</head>
<body>
<div align=center vertical-align=center>
<div class="centercolumn">
<A
HREF="http://www.domain.com/script.php?var1=value1&var2=value2">test
link</a>
</div>
<div class="footer">this is my footer.</div>
</div>
</div>
</body></html>
~~~~~~~~~~~~~~

--> the result for the link, when using "view source" function in
outlook, before sending manually the email is : <A
href="http://www.domain.com/script.php?var1=value1&amp;var2=value2">test
link</A> instead of <A
href="http://www.domain.com/script.php?var1=value1&var2=value2">test
link</A>

Regards,
Thanks in advance for your response.
Arnaud

Sue Mosher [MVP] a écrit:
 
Top