469,360 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

StreamWriter, StringWriter and encoding...

Hello,

i have a big problem with my email component, because each time i write the
generated message directly to the spooler, the streamwriter will write in
Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the message,
will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and QMAIL
reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(filename,true,Encoding.ASCII))
{
sw.Write(message);
}

Please help,
Regards
Stefano
Nov 16 '05 #1
6 30822
kinekine@digita wrote:
Hello,

i have a big problem with my email component, because each time i
write the generated message directly to the spooler, the streamwriter
will write in Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the
message, will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and
QMAIL reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new
StreamWriter(filename,true,Encoding.ASCII)) {
sw.Write(message);
}


Now I'm confused. This StreamWriter writes ASCII, which will drop any
non-7-bit character...

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 16 '05 #2

Try

new StreamWriter(filename,Encoding.Default)

"kinekine@digita" <ki************@discussions.microsoft.com> wrote in
message news:3B**********************************@microsof t.com...
Hello,

i have a big problem with my email component, because each time i write
the
generated message directly to the spooler, the streamwriter will write in
Unicode.

The file starts with a FF FE and is double byte.

This is a problem because when a mail server like QMAIL receive the
message,
will reject for malformed LF.

Infact, the file is Unicode and the normal CR/LF is (0D 00 0A 00) and
QMAIL
reading 00 0A fails.

I tried everithing...

The code:

StringWriter SW = new StringWriter(new StringBuilder());
SW.WriteLine("x-sender: <" + this._From.Address + ">");
[...]
string message = SW.ToString();
using (StreamWriter sw = new StreamWriter(filename,true,Encoding.ASCII))
{
sw.Write(message);
}

Please help,
Regards
Stefano

Nov 16 '05 #3
Already tried, with o without an encoding specified, will always save to
Unicode.

please note that the content is fully in ascii range.

Exists a function or a trick to save in single byte?

Stefano

"Michael S" wrote:

Try

new StreamWriter(filename,Encoding.Default)

"kinekine@digita" <ki************@discussions.microsoft.com> wrote in
message news:3B**********************************@microsof t.com...
Hello,

i have a big problem with my email component, because each time i write
the


Nov 16 '05 #4
kinekine@digita <ki************@discussions.microsoft.com> wrote:
Already tried, with o without an encoding specified, will always save to
Unicode.


In that case your code is wrong, or you're misdiagnosing the problem.
With no encoding specified, it should be using UTF-8.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hello Jon,

i can't post the whole class to the newsgroup because is very big, and
nothing can be stripped out or the result will be different.

I will send you the class privately, please take a look.

Regards,

Stefano

"Jon Skeet [C# MVP]" wrote:
kinekine@digita <ki************@discussions.microsoft.com> wrote:
Already tried, with o without an encoding specified, will always save to
Unicode.


In that case your code is wrong, or you're misdiagnosing the problem.
With no encoding specified, it should be using UTF-8.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
kinekine@digita <ki************@discussions.microsoft.com> wrote:
i can't post the whole class to the newsgroup because is very big, and
nothing can be stripped out or the result will be different.
I find that hard to believe, I'm afraid.
I will send you the class privately, please take a look.


I'll have a brief look, but if it's that big, it will probably take
longer than I've got time spare. As the person who understands the code
best, you're in the best position to cut it down (or start from scratch
to build up a short but complete program).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lou | last post: by
5 posts views Thread by Waldy | last post: by
4 posts views Thread by ASP Yaboh | last post: by
1 post views Thread by Anthony Nystrom | last post: by
1 post views Thread by Brad Wood | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.