gpt4 book ai didi

asp.net - 如何在发送电子邮件时插入换行符?

转载 作者:行者123 更新时间:2023-12-02 01:15:01 24 4
gpt4 key购买 nike

“\n”或“
”均无效。我试图在通过电子邮件发送自定义表单的内容时插入换行符:

protected void SubmitBtn_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
StringBuilder mailBody = new StringBuilder();
mailBody.Append("Company Name: " + companyText.Text.Trim() + "\n\n");
mailBody.Append("Name: " + firstNameText.Text.Trim() + " "
+ lastNameText.Text.Trim() + "\n\n");
mailBody.Append("Email: " + emailText.Text.Trim() + "\n\n");

if(!String.IsNullOrEmpty(tradeText.Text))
mailBody.Append("Trade: " + tradeText.Text.Trim() + "\n\n");

bool success = SendEmail(emailText.Text.Trim(),
companyText.Text.Trim(), "SubContractors Form Submission",
mailBody.ToString());
}
}

private bool SendEmail(string email, string name,
string subject, string message)
{
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(BlogSettings.Instance.Email, name);
mail.ReplyTo = new MailAddress(email, name);

mail.To.Add(BlogSettings.Instance.Email);
mail.Subject = subject;
mail.Body += message;

if (Utils.SendMailMessage(mail).Length > 0)
{
return false;
};
}
return true;
}

更新:

我最终
开始工作了。它不起作用的原因是因为这是我从联系表中获得的原始代码:

mail.Body += message.Replace("\n\n", "<br />");

MailMessage.IsBodyHtml 在核心库代码中设置为 true。

最佳答案

您可以使用:

关于asp.net - 如何在发送电子邮件时插入换行符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12644955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com