3

i am sending email through my application using the following code of c#

 myMail.Body = TextBox1.Text+ txtName.Text+ txtCName.Text+ txtAddress.Text+ TextBox1.Text+ txtCity.Text+ txtState.Text+ txtCountry.Text+ txtPhone.Text+ Fax.Text+ txtCell.Text+ txtEmail.Text+ txtPrinting.Text; myMail.BodyEncoding = System.Text.Encoding.UTF8; 

but i am getting mail in this form "sheerazahmedShehzoreHyderabadsheerazHyderabadSindhPakistan03453594552034598750258741sheery_1@hotmail.comsingle" i.e merging all values, i want each value of textboxt in a separate new line i.e

Sheeraz Ahmed Shehzore Hyderabad 

etc.

5 Answers 5

10
StringBuilder sb = new StringBuilder(); sb.AppendLine(TextBox1.Text); sb.AppendLine(txtName.Text); ... myMail.Body = sb.ToString(); 
Sign up to request clarification or add additional context in comments.

Comments

7
myMail.Body = TextBox1.Text + Environment.NewLine + txtName.Text+ Environment.NewLine + txtCName.Text+ Environment.NewLine + txtAddress.Text+ Environment.NewLine + TextBox1.Text+ Environment.NewLine + txtCity.Text+ Environment.NewLine + txtState.Text+ Environment.NewLine + txtCountry.Text+ Environment.NewLine + txtPhone.Text+ Environment.NewLine + Fax.Text+ Environment.NewLine + txtCell.Text+ Environment.NewLine + txtEmail.Text+ Environment.NewLine + txtPrinting.Text; myMail.BodyEncoding = System.Text.Encoding.UTF8; 

Or better yet, use a stringbuilder or string.Format

StringBuilder bodyBuilder = new StringBuilder(""); bodyBuilder .AppendLine(TextBox1.Text); bodyBuilder .AppendLine(txtName.Text); bodyBuilder .AppendLine(txtCName.Text); bodyBuilder .AppendLine(txtAddress.Text); // etc. myMail.Body = bodyBuilder .ToString(); 

or

myMail.Body = String.Format("{0}{1}{2}{1}{3}{1} ... ", TextBox1.Text, Environment.NewLine, txtCName.Text, txtAddress.Text -- etc... 

Comments

1
myMail.Body = TextBox1.Text+ Environment.NewLine + txtName.Text+ Environment.NewLine + txtCName.Text+ Environment.NewLine + txtAddress.Text+ Environment.NewLine + TextBox1.Text+ Environment.NewLine + txtCity.Text+ Environment.NewLine + txtState.Text+ Environment.NewLine + txtCountry.Text+ Environment.NewLine + txtPhone.Text+ Environment.NewLine + Fax.Text+ Environment.NewLine + txtCell.Text+ Environment.NewLine + txtEmail.Text+ Environment.NewLine + txtPrinting.Text; 

Comments

0

Use String.Format in combination with Environment.NewLine.

e.g.

String.Format("{0}{1}{2}{1}{3}", "ValueOfTextbox1", Environment.NewLine, "ValueOfTextbox2", "ValueOfTextbox3"); 

You only have to define one placeholder in the string for Environment.NewLine and you can reuse it.

Comments

0
result = text1 + Environment.NewLine + text2 + Environment.NewLine + text3; 

this will put text1,text2 and text3 in a separate line.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.