+1 vote

I am using the 'MailBuilder' in a C# application where there will possibly be more than 1 line of text in the body of the message. I will receive the data 1 line at a time. Example...

I have 3 pets (listed below):
Dog
Cat
Turtle

If I use the code in a loop like the following where 'lcRead' is 1 line of the data...

string lcMessage = lcRead.Substring(5).Trim(); //Reads each line individually
builder.Text = lcMessage;

The builder.Text will only contain 1 line (which is "Turtle") when the loop completes.

How do I include all lines?

by (1.3k points)

1 Answer

+1 vote
 
Best answer

You need to use \r\n (CRLF) as with regular .NET strings:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@example.com", "Alice"));
builder.To.Add(new MailBox("bob@example.com", "Bob"));
builder.Subject = "Test";


builder.Text = "first line\r\n second line\r\n third line";


IMail email = builder.Create();
by (301k points)
selected by
Your answer is right on the money...  I surprised myself in coming up with the answer (trial and error) yesterday afternoon on my own.  Thank you for your reply!
...