Having trouble with Environment.NewLine in email body

  • Thread starter Thread starter Kevin Blount
  • Start date Start date
K

Kevin Blount

I've been trying all morning to find a way that will let me add new
lines to a string that will form the body of an email. The problem is
that some lines are not appearing as new line, but rather are being
appended to existing lines. Here's my (cut down) code:

string sbInstructions = string.Empty;
char endOfLine = '\n';

sbInstructions += "[Instructions]" + endOfLine;
sbInstructions += "DupCheck=email" + endOfLine;
sbInstructions += "SaveThis=" + gmEmailSubject + endOfLine;

int iLoopCount = 1;
do
{
sbInstructions += "OnNewSendEmail" + iLoopCount + "=" +
EmailSubject.Trim() + endOfLine;
sbInstructions += "OnDupSendEmail" + iLoopCount + "=" +
EmailSubject.Trim() + endOfLine;

sbInstructions += "cs" + iLoopCount + "_RecType=P" + endOfLine;
sbInstructions += "cs" + iLoopCount + "_Contact=P" + gmEmailSubject +
endOfLine;
} while (iLoopCount != contactsLoop);

In place of using endOfLine I've tried hard-coding '\n' and
Environment.NewLine, and I even tried using a StringBuilder and using
..AppendLine, but the result is this:

[Instructions]
DupCheck=email
SaveThis=Demo CD Request
OnNewSendEmail1=ESPDL,NEW,Demo CD Request OnDupSendEmail1=ESPDL,NEW,Demo
CD Request cs1_RecType=P cs1_Contact=test subject

where the result I need to this:

[Instructions]
DupCheck=email
SaveThis=Demo CD Request
OnNewSendEmail1=ESPDL,NEW,Demo CD Request
OnDupSendEmail1=ESPDL,NEW,Demo CD Request
cs1_RecType=P
cs1_Contact=test subject


any ideas why I can't get my new lines to work properly?
 
Hi Mel,

Thanks for the reply. Unfortunately my email is not set to HTML, so
using "<br>" tags won't help here.

Any other ideas?

Kevin
use the html tag of <br> for new line since your email is set to html

Kevin Blount said:
I've been trying all morning to find a way that will let me add new lines
to a string that will form the body of an email. The problem is that some
lines are not appearing as new line, but rather are being appended to
existing lines. Here's my (cut down) code:

string sbInstructions = string.Empty;
char endOfLine = '\n';

sbInstructions += "[Instructions]" + endOfLine;
sbInstructions += "DupCheck=email" + endOfLine;
sbInstructions += "SaveThis=" + gmEmailSubject + endOfLine;

int iLoopCount = 1;
do
{
sbInstructions += "OnNewSendEmail" + iLoopCount + "=" +
EmailSubject.Trim() + endOfLine;
sbInstructions += "OnDupSendEmail" + iLoopCount + "=" +
EmailSubject.Trim() + endOfLine;

sbInstructions += "cs" + iLoopCount + "_RecType=P" + endOfLine;
sbInstructions += "cs" + iLoopCount + "_Contact=P" + gmEmailSubject +
endOfLine;
} while (iLoopCount != contactsLoop);

In place of using endOfLine I've tried hard-coding '\n' and
Environment.NewLine, and I even tried using a StringBuilder and using
.AppendLine, but the result is this:

[Instructions]
DupCheck=email
SaveThis=Demo CD Request
OnNewSendEmail1=ESPDL,NEW,Demo CD Request OnDupSendEmail1=ESPDL,NEW,Demo
CD Request cs1_RecType=P cs1_Contact=test subject

where the result I need to this:

[Instructions]
DupCheck=email
SaveThis=Demo CD Request
OnNewSendEmail1=ESPDL,NEW,Demo CD Request
OnDupSendEmail1=ESPDL,NEW,Demo CD Request
cs1_RecType=P
cs1_Contact=test subject


any ideas why I can't get my new lines to work properly?
 
Back
Top