如何在 C# Webservice 中换行

How to do new Line in C# Webservice

我正在尝试使用 Web 服务(asmx 中的 SOAP)创建新行,而不是让它使用“\n”发送带有新行的电子邮件,它只是显示一条直线。

我的代码如下所示:

[WebMethod]
public bool SendCashBagSerial(string email, string fullname, string SerialNumCode, string purpleworksemail) 
{
    string to = email; //To address    
    string from = purpleworksemail;
    MailMessage message = new MailMessage(from, to);

    string EmailBody = "Dear "+ fullname +"\n Your CashBag Serial is : "+ SerialNumCode + "\n Please Quote this Number to Complete your Request. \n Regards, \n Purpleworks \n ";
    message.Subject = "Your Cash Bag Serial!";
    message.Body = EmailBody;
    message.BodyEncoding = Encoding.UTF8;
    message.IsBodyHtml = true;
    SmtpClient client = new SmtpClient("smtp.office365.com", 587);
    System.Net.NetworkCredential basicCredential1 = new System.Net.NetworkCredential("*******@*************", "*******");
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = basicCredential1;
    try
    {
        client.Send(message);
    }
    catch(Exception ex)
    {
        throw ex;
    }

    return true;
}

我是不是做错了什么?

换行符通常是2个字符,一个换行符和一个回车符return。要复制这个,你需要 \r\n... 但你的电子邮件是 html

message.IsBodyHtml = true;

所以你需要使用<br>