bulletproof .NET class or method for entity translation for e-mail sends?

G

Guest

I implement a lot of "send to friend" functionalities as well as utilizing a
lot of content that's been scraped from other places on the web.I built
these tools using Classic ASP.

Some classes of entities do not translate correctly to e-mail and are
rendered as question marks in e-mail clients.

To deal with content that had extended characters and entities (curly
quotes, etc.) I wrote translation functions that converted the "bad" strings
of characters into acceptable ones for the e-mail clients that commonly
parse our mail. These translation functions are long, and occassionally they
miss unusual entities because I haven't implemented every last exception.

I am wondering if there is a method in .NET that will reliably do this
translation for me. For that matter, I'm wondering if there was a method in
Classic ASP that would have done the same thing.

If someone can point me to the right method, and the right set of base
concepts here I'd appreciate it.

Thanks,
-KF
 
W

Walter Wang [MSFT]

Hi KF,

I'm not sure if I fully understand your question. So please correct me if
I've missed anything.

If you want to send email in .NET 2.0, you can use System.Net.Mail
(http://msdn2.microsoft.com/en-us/library/system.net.mail.aspx).
MailMessage.BodyEncoding can let you set the encoding you wanted to send
the email. I believe this will automatically handle the non-ASCII
characters in the message.

If you want to encode non-ASCII characters by hand (for example, in classic
ASP), I think you can refer to "Character entity references in HTML 4"
(http://www.w3.org/TR/html4/sgml/entities.html) for how to encode them. For
example, curly quotes are encoded as “ and ”.

Here's some code for your reference in VBScript:

Function EncodeHtml( strInput )
If IsNull(strInput) Then
EncodeHtml = ""
Exit Function
End If

dim cnt, c
for cnt = 1 to len(strInput)
c = CLng(ascw(mid(strInput,cnt,1)))

' Fix for char codes larger then 23768
' ascw only returns an integer and we wrap
if ( c < 0 ) then
c = CLng(c) + 65536
end if

if ( _
( ( c > 96 ) and ( c < 123 ) ) or _
( ( c > 64 ) and ( c < 91 ) ) or _
( c = 32 ) or _
( ( c > 47 ) and ( c < 58 ) ) or _
( c = 46 ) or _
( c = 44 ) or _
( c = 45 ) or _
( c = 95 )) Then
EncodeHtml = EncodeHtml & chrw(c)
Else
EncodeHtml = EncodeHtml & "&#" & c & ";"
End If
next
End Function


Hope this helps.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks Walter. You understood my question perfectly. I already have
character entity translation functions in place on my classic ASP apps, but
was curious if I had somehow missed somethings from the cASP world that's as
complete as MailMessage.BodyEncoding.

Thanks for the help.

-KF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top