473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Sending mail message with unicode text

Hello.
I have a problem with sending Unicode text in mail message.
So what I do:

First of all I have some template file like this:
=================================
<html>
<head><title>Test Message</title></head>
<body>
<p>Hello {0}</p>
</body>
</html>
=================================

This text will include Unicode text too.
Late I want to load this text and replace "{0}" with some value and send it
by mail.
then I do following:
=================================
// Read message text from predefined file
System.IO.TextReader textReader = new System.IO.StreamReader(fileName);
text = textReader.ReadToEnd();
textReader.Close();

// Assign message
MailMessage mailMessage = new MailMessage();
mailMessage.From = "so**@mail.com";
mailMessage.To = "so**@mail.com";
mailMessage.Subject = "Test";
mailMessage.Body = String.Format(text, "some UNICODE text");
mailMessage.BodyFormat = MailFormat.Html;
mailMessage.BodyEncoding = Encoding.Unicode;

// Send message
SmtpMail.SmtpServer = Settings.GetValue("SmtpServer");
SmtpMail.Send(mailMessage);
=================================

Now about the problem:
when I got message sent by this code it looks something like this: (actually
this is an anothe mail)
=================================
< h t m l > < h e a d > < t i t l e > R e g i s t e r i n g p r o p e r t y
< / t i t l e > < / h e a d > < b o d y > < p > < b > T h a n k y o u f o r
r e g i s t e r i n g y o u r p r o p e r t y w i t h R i g h t M o v i e ..
g e < / b > < / p > < p > Y o u r r e g i s t r a t i o n n u m b e r i s 1
9 3 3 9 6 a n d y o u s h o u l d q u o t e t h i s o n a n y c o r r e s p
o n d e n c e .. < / p > < p > Y o u r p r o p e r t y w i l l b e d i s p l
a y e d o n t h e R i g h t M o v i e .. g e w e b s i t e u n t i l 0 3 ..
1 2 .. 2 0 0 5 .. Y o u m a y r e n e w o r u p d a t e y o u r r e g i s t
r a t i o n a t a n y t i m e b y c l i c k i n g o n < a h r e f = " h t t
p : / / 2 1 3 .. 1 5 7 .. 2 0 1 .. 2 3 4 / R i g h t M o v e / P r o p e r t
y R e n e w .. a s p x ? r e g n u m = 1 9 3 3 9 6 " > h t t p : / / 2 1 3
... 1 5 7 .. 2 0 1 .. 2 3 4 / R i g h t M o v e / P r o p e r t y R e n e w
... a s p x ? r e g n u m = 1 9 3 3 9 6 < / a > .. < / p > < p > T h i s s e
r v i c e i s p r o v i d e d F R E E O F C H A R G E , s o p l e a s e t e
l l e v e r y o n e a b o u t R i g h t M o v i e .. g e .. < / p > < p > <
u > < b > D e t a i l s o f P r o p e r t y : < / b > < / u > < / p > < p >
< b > D i s p l a y e d U n t i l : < / b > 0 3 .. 1 2 .. 2 0 0 5 < b r > <
b > T y p e o f p r o p e r t y o r l a n d : < / b > ? ? ? ? ? < b r > < b
R o o m s : < / b > 4 ? ? ? ? ? < b r > < b > R e c e p t i o n r o o m s : < / b > 1 ? ? ? ? ? ? ? ? ? ? ? ? ? < b r > < b > A s k i n g P r i c e :
< / b > $ 9 9 .. 0 0 < b r > < b > H o u s e / A p p a r t m e n t # : < / b 9 < b r > < b > S t r e e t : < / b > ? ? ? 9 9 9 < b r > < b > D i s t r i c t a n d T o w n : < / b > ? ? ? ? ? ? ? < b r > < b > C o n t a c t : <
/ b > 9 9 9 < b r > < b > T e l e p h o n e : < / b > 9 9 9 < b r > < b > F
a x : < / b > < b r > < b > M o b i l e : < / b > < b r > < b > E - m a i l
: < / b > < a h r e f = " m a i l t o : d a v i d @ d s l .. g e " > d a v i
d @ d s l .. g e < / a > < b r > < b > E s t a t e A g e n t : < / b > ? ? ?
< b r > < b > P r o p e r t y D e s c r i p t i o n : < / b > 9 9 9 < b r >
< b > S t a t u s : < / b > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < b r < b > E n t r y t y p e : < / b > ? ? ? ? ? ? ? ? ? ? ? < / p > < p > R i

g h t M o v i e .. g e a c c e p t s n o r e s p o n s i b i l i t y f o r t
h e a c c u r a c y o r a v a i l a b i l i t y o f t h e i n f o r m a t i
o n d i s p l a y e d o n i t s w e b s i t e a n d a c c e p t s n o l i a
b i l i t y f o r l o s s o f e a r n i n g s o r l o s s o f c a p i t a l
g a i n s t h r o u g h u s e o f i t s s e r v i c e s .. < / p > < / b o d
y > < / h t m l >
=================================

When I don't use mailMessage.BodyEncoding = Encoding.Unicode; it send normal
mail but with "?" character instead Unicode symbols.

So how can I load from file then replace some values and send HTML format
Unicode text?

Thank you.
Nov 19 '05 #1
1 6868
I think it's the way you're reading in the file. Try using the
StreamReader constructor that specifies the encoding of the file as
well. E.g.:

System.IO.TextReader textReader = new System.IO.StreamReader(fileName,
System.Text.Encoding.Unicode);

I think that will do the trick.

HTH,
Kevin
David Dvali wrote:
Hello.
I have a problem with sending Unicode text in mail message.
So what I do:

First of all I have some template file like this:
=================================
<html>
<head><title>Test Message</title></head>
<body>
<p>Hello {0}</p>
</body>
</html>
=================================

This text will include Unicode text too.
Late I want to load this text and replace "{0}" with some value and send it
by mail.
then I do following:
=================================
// Read message text from predefined file
System.IO.TextReader textReader = new System.IO.StreamReader(fileName);
text = textReader.ReadToEnd();
textReader.Close();

// Assign message
MailMessage mailMessage = new MailMessage();
mailMessage.From = "so**@mail.com";
mailMessage.To = "so**@mail.com";
mailMessage.Subject = "Test";
mailMessage.Body = String.Format(text, "some UNICODE text");
mailMessage.BodyFormat = MailFormat.Html;
mailMessage.BodyEncoding = Encoding.Unicode;

// Send message
SmtpMail.SmtpServer = Settings.GetValue("SmtpServer");
SmtpMail.Send(mailMessage);
=================================

Now about the problem:
when I got message sent by this code it looks something like this: (actually
this is an anothe mail)
=================================
< h t m l > < h e a d > < t i t l e > R e g i s t e r i n g p r o p e r t y
< / t i t l e > < / h e a d > < b o d y > < p > < b > T h a n k y o u f o r
r e g i s t e r i n g y o u r p r o p e r t y w i t h R i g h t M o v i e ..
g e < / b > < / p > < p > Y o u r r e g i s t r a t i o n n u m b e r i s 1
9 3 3 9 6 a n d y o u s h o u l d q u o t e t h i s o n a n y c o r r e s p
o n d e n c e .. < / p > < p > Y o u r p r o p e r t y w i l l b e d i s p l
a y e d o n t h e R i g h t M o v i e .. g e w e b s i t e u n t i l 0 3 ..
1 2 .. 2 0 0 5 .. Y o u m a y r e n e w o r u p d a t e y o u r r e g i s t
r a t i o n a t a n y t i m e b y c l i c k i n g o n < a h r e f = " h t t
p : / / 2 1 3 .. 1 5 7 .. 2 0 1 .. 2 3 4 / R i g h t M o v e / P r o p e r t
y R e n e w .. a s p x ? r e g n u m = 1 9 3 3 9 6 " > h t t p : / / 2 1 3
.. 1 5 7 .. 2 0 1 .. 2 3 4 / R i g h t M o v e / P r o p e r t y R e n e w
.. a s p x ? r e g n u m = 1 9 3 3 9 6 < / a > .. < / p > < p > T h i s s e
r v i c e i s p r o v i d e d F R E E O F C H A R G E , s o p l e a s e t e
l l e v e r y o n e a b o u t R i g h t M o v i e .. g e .. < / p > < p > <
u > < b > D e t a i l s o f P r o p e r t y : < / b > < / u > < / p > < p >
< b > D i s p l a y e d U n t i l : < / b > 0 3 .. 1 2 .. 2 0 0 5 < b r > <
b > T y p e o f p r o p e r t y o r l a n d : < / b > ? ? ? ? ? < b r > < b
> R o o m s : < / b > 4 ? ? ? ? ? < b r > < b > R e c e p t i o n r o o m s

: < / b > 1 ? ? ? ? ? ? ? ? ? ? ? ? ? < b r > < b > A s k i n g P r i c e :
< / b > $ 9 9 .. 0 0 < b r > < b > H o u s e / A p p a r t m e n t # : < / b
> 9 < b r > < b > S t r e e t : < / b > ? ? ? 9 9 9 < b r > < b > D i s t r

i c t a n d T o w n : < / b > ? ? ? ? ? ? ? < b r > < b > C o n t a c t : <
/ b > 9 9 9 < b r > < b > T e l e p h o n e : < / b > 9 9 9 < b r > < b > F
a x : < / b > < b r > < b > M o b i l e : < / b > < b r > < b > E - m a i l
: < / b > < a h r e f = " m a i l t o : d a v i d @ d s l .. g e " > d a v i
d @ d s l .. g e < / a > < b r > < b > E s t a t e A g e n t : < / b > ? ? ?
< b r > < b > P r o p e r t y D e s c r i p t i o n : < / b > 9 9 9 < b r >
< b > S t a t u s : < / b > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? < b r
> < b > E n t r y t y p e : < / b > ? ? ? ? ? ? ? ? ? ? ? < / p > < p > R i

g h t M o v i e .. g e a c c e p t s n o r e s p o n s i b i l i t y f o r t
h e a c c u r a c y o r a v a i l a b i l i t y o f t h e i n f o r m a t i
o n d i s p l a y e d o n i t s w e b s i t e a n d a c c e p t s n o l i a
b i l i t y f o r l o s s o f e a r n i n g s o r l o s s o f c a p i t a l
g a i n s t h r o u g h u s e o f i t s s e r v i c e s .. < / p > < / b o d
y > < / h t m l >
=================================

When I don't use mailMessage.BodyEncoding = Encoding.Unicode; it send normal
mail but with "?" character instead Unicode symbols.

So how can I load from file then replace some values and send HTML format
Unicode text?

Thank you.


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: BrentonMCA | last post by:
I want to be able to serialise a .Net object and send the resulting XML by TCP. How can I extract the serialised XML as a string?
0
by: David Dvali | last post by:
Hello. I have a problem with sending Unicode text in mail message. So what I do: First of all I have some template file like this: ================================= <html> <head><title>Test...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
0
by: michi | last post by:
Hello :) When I execute following asp.net code **** Web.Mail.SmtpMail.SmtpServer = "squadron" Web.Mail.SmtpMail.Send("wwwmike@gmx.ch", "wwwmike@gmx.ch", "subj", "message") ****
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
4
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I use: Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text, txtBody.Text) Dim emailClient As New SmtpClient(txtSMTPServer.Text) emailClient.Send(message) And its...
8
by: Marty | last post by:
I'm having issues sending an email to an "@page.nextel.com" email address. I can send to any other email address fine, but when I try the page.nextel.com it gives me this error: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.