System.Web.Mail - Bad Bug

D

David Connors

Hello,

I can't see another appropriate group to post this in. system.web.mail has a
bad bug in it where it is not conforming to RCF822. The old pre-dotnet
CDONTS obects did not have this behaviour.

The problem is that system.web.mail sends messages with naked line feeds in
them rather than escaping them to be a cr and an lf. An lf on a line by
itself is invalid in an SMTP message.

Repro code is attached below. This message will never be able to be
delivered to a qmail server (of which there are many).

The code is:

using System;
using System.Text;
using System.Web;
using System.Web.Mail;

namespace theEmailTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
MailMessage mm = new MailMessage();

mm.BodyEncoding = Encoding.UTF8;

mm.To = "(e-mail address removed)";
mm.From = "(e-mail address removed)";
mm.Subject = "Test Subject";
mm.BodyFormat = MailFormat.Html;

mm.Body = "Test Body\n\nEnd";

SmtpMail.Send(mm);
}
}
}


The following VBS code does cause the LF characters to be correctly escaped
to a CR + LF pair prior to submitting the message to the local mail queue
for delivery.

Option Explicit

Dim objCDONTS

Set objCDONTS = CreateObject("CDONTS.NewMail")

objCDONTS.To = "(e-mail address removed)"
objCDONTS.From = "(e-mail address removed)"
objCDONTS.Subject = "Test Subject"
objCDONTS.Body = "Test Body" & chr(10) & chr(10) & "End3"
objCDONTS.Send

Set objCDONTS = Nothing

MsgBox "Done."

Any pointers on getting this fixed?

David.
 
O

Ollie Riches

Is there a reason why you aren't using Environment.NewLine instead of '\n' ?

HTH

Ollie Riches
 
D

David Connors

Ollie said:
Is there a reason why you aren't using Environment.NewLine instead of '\n' ?

HTH

The templates being sent come from external sources and are read in
from files rather than being composited programatically.

Environment.NewLine should presumably return only a line feed character
on UNIX implementations of .NET anyway seeing as that's the native line
termination sequence on UNIX.

I think the bug still stands that system.web.mail should not send mails
that are non-conformant with the relevant RFCs.

David.
 
O

Ollie Riches

I don't have in depth knowledge of the RFC's for this but why don't you use
a regular expression to replace '\n' with the required cr & lf.

HTH

Ollie Riches
 
D

David Connors

Hi Ollie,

We've already done that. I'm posting it here to get the bug fixed in
the framework so we don't have to implement work arounds.

David.
 

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

Top