.Net.Mail新行

0 c# mailmessage

我正在使用.Net.Mail发送短信,但我在插入新行时遇到问题.我已经搜索了包括StackOverflow在内的互联网,以寻找实现此目的的方法.我发现了几个但没有它们起作用.我使用StringBuilder来构建消息的主体,但是添加新行或空行确实会在消息中插入新行.我也试过"\n"和其他几种方法但似乎没什么用.我在下面添加了我的代码.有谁知道我怎么做到这一点.提前感谢您提供的任何帮助.

string cellPhone = reader.GetString(reader.GetOrdinal("CellPhone"));
string suffix = reader.GetString(reader.GetOrdinal("Suffix"));
StringBuilder body = new StringBuilder();
cellPhone = cellPhone.Trim().Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
if (!suffix.StartsWith("@"))
{
    suffix = "@" + suffix;
}
string address = cellPhone + suffix;
reader.Close();

EMail email = new EMail("mail.yyy.com");
email.IsHTML = true;
email.Subject = "Sales Lead from yyy.com";
email.Add_ToAddress(address, false);
body.AppendLine(" ");
body.AppendLine("Name: " + this.tbSalesLeadName2.Text + "EMail: mailto: " + this.tbSalesLeadEmail2.Text);

if (!this.chkSalesLeadEmail2.Checked)  //&& (!this.hidCellPhoneProvider.Value.Equals("0", StringComparison.InvariantCultureIgnoreCase)))
{
    body.AppendLine("Phone: " + this.tbSalesLeadPhone2.Text);
    body.AppendLine("Cell Phone: " + this.tbSalesLeadCellPhone.Text);
}

body.AppendLine(" ");
body.AppendLine(" ");
body.AppendLine("Comments: " + this.tbSalesLeadComments2.Text);
body.AppendLine(" ");
body.AppendLine(" ");
body.AppendLine("***To respond start a new text thread with the cell phone number listed above");
email.Body = body.ToString();
email.From = "xxx@yyy.com";
email.Send_Mail();
Run Code Online (Sandbox Code Playgroud)

Hei*_*nzi 5

email.IsHTML = true;
Run Code Online (Sandbox Code Playgroud)

你说你的身体是HTML格式,但事实并非如此.

您有两种方法可以解决这个问题:

  1. 设置IsHTML为false,您的换行符应该有效.

  2. 将您的身体格式化为真实的 HTML,即HtmlEncode用于您的数据和<br>换行符.