Link to home
Start Free TrialLog in
Avatar of Member_2_1316035
Member_2_1316035

asked on

"! " is added to my long email message body ramdomly.

My application (both asp and asp.net) sends email notice.  An exclamation mark is randomly added to my email message body.  I search Internet and found similar bugger in PHP email.  If I cut the message very short, the mark goes away.

http://www.tek-tips.com/viewthread.cfm?qid=913854

As one expert suggests, this could be caused by character encoding that is triggered by use of high-hex-value characters or long lines in the body of the email.

Please help.

Here is the problematic codes, which is in a loop.

StringBuilder bodyMsg = new StringBuilder();
bodyMsg.Append("<p><b>Dear ");
bodyMsg.Append(fName);

..... long message

MailMessage Message = new MailMessage();
Message.To = "sss@here.com";
Message.From = "ddd@there.com";
Message.Subject = "a subject of length like jasdlfkjsadfjsd flsdfjasdjf fdjasldfjasldfjlsdfjsdaj";
Message.Body = bodyMsg.ToString();
Message.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = "there.com";
SmtpMail.Send(Message);
Avatar of yellowjetski
yellowjetski


When you are debugging, try to copy and paste the bodyMsg.ToString() to a html file and see if you are missing or have any extra html tags

Message.Priority = MailPriority.Normal;//Add this line to just make sure.
SOLUTION
Avatar of Razzie_
Razzie_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Beginning with V1.1 of the framework, System.Web.Mail does no longer use Quoted-Printable encoding on HTML mails. Therefore, you should make sure yourself that no line exceeds 76 characters, which is the limit one should use for trasnport over SMTP. Adding line breaks may solve your problem.
Also, make sure that no line starts with a "." since this is not well handled by some servers.
Avatar of Member_2_1316035

ASKER

AvonWyss,

Thanks a million for your input.  Does "no line exceeds 76 characters" mean I need to use html code to control the line length, instead of letting recipient's email client to wrap the lines up?  If I have to force wrapup using html tags, then I have to.  Otherwise, I may get somethings like the following if automatic wrapup happens before 76 characters.

12345678902234567890323456789042345678905234567890623456789
0723456(foreced wrapup)
1234567890223456789032345678904234567890523456789062345678907
23456(foreced wrapup)
1234567890223456789032345678904234567890523456789062345678907
23456(foreced wrapup)

Biang
No, I think there is a misunderstanding. The thing is that the lines of the HTML source (!) must not exceed 76 charachters in length to be fully compatile with the SMTP specifications. Since HTML allows you to use line breaks which are not transferred to the output (just a whitespace, except for <pre>-sections), this usually does not change the visible result of your mail. Basically, it's goot enough to write some code that will split up the HTML source code into lines with a length shorter or equal to 76 characters. You usually can add line breaks at any whitespace or tag start/end without changing the finale HTML result.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
AvonWyss,

Great!!! It works.  Two more questions.

1) where I can find the SMTP specifications

2) wrap method wraps the line in the middle of link, like

"xxxxxxxx xxxx htt://ww
w.xxxxxxxxx"

When I look at the page, the link ends up with "http://ww w.xxxxxxx".  A space looks like added.  But in html code is not.  Any further suggestion?

Thanks a million for your advice, AvonWyss.

Bin

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial