StringBuilder and objMail

R

Rick

I am new to ASP.NET so please be gentle :)
I am trying to build an text (not HTML) email. I am putting together the
string that will be the body of the email but the formatting keeps getting
messed up. See code below.

Thanks in advance for any help you can give!

I want it to look like this...

Thank you for ordering from mycompany.com!

Your order is being billed to:
John Smith

******** But it keeps coming out like **************

Thank you for ordering from mycompany.com!Your order is being billed to: "
John Smith


******* Here is my code ********
Dim sEmail As New System.Text.StringBuilder

sEmail.Append("Thank you for ordering from mycompany.com!" & Chr(13))
sEmail.Append("Your order is being billed to: " & Chr(34))
sEmail.Append(Chr(32) & rdrMbrs.Item("fullname"))

objMail.Body = sEmail.toString()
 
G

Gaurav Vaish \(MasterGaurav\)

******** But it keeps coming out like **************

Thank you for ordering from mycompany.com!Your order is being billed to: "
John Smith


******* Here is my code ********
sEmail.Append("Thank you for ordering from mycompany.com!" & Chr(13))
sEmail.Append("Your order is being billed to: " & Chr(34))
sEmail.Append(Chr(32) & rdrMbrs.Item("fullname"))

The newline in the internet world is not Chr(13) which is only
carriage-return.

The newline if CRLF:
Chr(13) & Chr(10)

I'm not sure but I think vbCrlf - constant - should be automatically
available to VB.Net programmers. It used to be there in VB6 and I think
should exist even now.

See this page for a good discussion:
http://en.wikipedia.org/wiki/Newline


HTH

--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
W

Walter Wang [MSFT]

I agree with Gaurav. However, a better approach is to use
System.Environment.NewLine.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Gaurav Vaish \(MasterGaurav\)

I agree with Gaurav. However, a better approach is to use
System.Environment.NewLine.

Not sure if System.Environment.NewLine is a good approach since again, we
are going to OS specific newline which is CRLF on Windows, CR on Mac and LF
on Unix/Linux etc.

Ok... if we are working with Microsoft .Net Framework, we know that we are
on Windows and it will translate to CRLF.

But I would like to play safe. Although an impossible probability today, but
what if Microsoft plans to release it on other OS as well ;)


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
W

Walter Wang [MSFT]

Hi Gaurav,

Using System.Environment.NewLine is the preferred way to represent a
"NewLine"; although you're right that the internal implementation of this
read-only property currently is implemented as:

public static string NewLine
{
get
{
return "\r\n";
}
}


However, consider someday your code is going to run on other platform, your
code doesn't have to be modified since you're calling into the BCL (Base
Class Library). I believe the BCL on different platform should return the
new line constant accordingly.


#Brad Abrams : Pet Peeve #493: Console.WriteLine ("\n")
http://blogs.msdn.com/brada/archive/2004/08/08/211053.aspx

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Gaurav Vaish \(MasterGaurav\)

However, consider someday your code is going to run on other platform,
your
code doesn't have to be modified since you're calling into the BCL (Base
Class Library). I believe the BCL on different platform should return the
new line constant accordingly.

I agree. I use it as the way to write a new-line (mainly since I also work
with Mono at times).

But hey! Hold on... the original problem was in the mail-message being sent.
In the mail-message composed, Environment.NewLine is definitely a very bad
choice.
There cannot be any choice other than CRLF (="\r\n" or "Chr(13) & Chr(10)").

I still hold on to my point that Environment.NewLine should not be used to
indicate a new-line while composing a mail.



--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
R

Rick

This worked great!!! Chr(13) & Chr(10) Thanks everyone for all you help.
One more thing why does the tab also not work? Chr(32)

Thanks Again!
 
M

Mark Rae

This worked great!!! Chr(13) & Chr(10) Thanks everyone for all you help.
One more thing why does the tab also not work? Chr(32)

Chr(32) is a <space>
Chr(9) is a <tab>
 
W

Walter Wang [MSFT]

My apology for ignoring the requirement is to use the line breaks in email
message. According to RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt), the
Line Break in a text body must use a CRLF sequence.

I hope I didn't cause too much confusion.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Gaurav Vaish \(www.edujini-labs.com\)

My apology for ignoring the requirement is to use the line breaks in email
message. According to RFC 2045 (http://www.ietf.org/rfc/rfc2045.txt), the
Line Break in a text body must use a CRLF sequence.

That's ok.
btw, that's not just an RFC-2045 requirement but also elsewhere like in HTTP
etc.
CRLF is the "NewLine" of the "Internet" and specifically, "the Web".
I hope I didn't cause too much confusion.

I hope not. :)


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujini-labs.com
-----------------------------------------
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top