By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,967 Members | 1,596 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,967 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Dec 19 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/lib...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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Dec 20 '06 #2

P: n/a

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

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:tV**************@TK2MSFTNGHUB02.phx.gbl...
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/lib...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 (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
==================================================

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

Dec 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.