[英]How do you get line breaks to show up in web email message using MVC smtp message body?
我要么瘋了,要么沒有我能理解的先前答案(可能會發生)。
Gmail在電子郵件正文中顯示了此信息(在devbox上使用IIS,因此在鏈接中使用“ localhost”):
:點擊此鏈接,請確認您的帳戶的http://本地主機:53891 /帳號/ ConfirmEmail用戶id = 526b54e1-2275-4bb0-bc8347289f413a69&代碼= ErXrRF8f%2BPZFK43WxwxQJjfT7%2BIIgd6HhglTNq8btRDdRZwbBxgwtmtuGhBDozgr9vyy2cy%2Bs0yweATeY4Hgv6BmjtOK7fJ7S2rS%2B8ShjhILM7kXZNqMBK4sTGSHoSozURZRgfTQcSB2OBgTFk8v%2BvlslF5Xsilz? %2Bd0OwnJz6KwOqNzzMrB6DgUyjUAIOJTt或點擊,復制瀏覽器中的鏈接。
當我單擊它並注冊我時它就起作用了,但是我似乎無法格式化它,因此它有換行符/換行符。 魔鬼在細節上哈哈!
這是我的MVC IdentityConfig.cs發送電子郵件:
string html = HttpUtility.HtmlEncode("Please confirm your account by clicking this link: " +
Environment.NewLine + Environment.NewLine + message.Body);
html += HttpUtility.HtmlEncode(Environment.NewLine);
html += HttpUtility.HtmlEncode(Environment.NewLine);
html += HttpUtility.HtmlEncode(Environment.NewLine);
html += HttpUtility.HtmlEncode("Or click on and copy the link in your browser.");
html.Replace(Environment.NewLine, "<br />");
您沒有為HTML提供替換內容。
html = html.Replace(Environment.NewLine, "<br />");
對?
編輯:進一步的例子-https: //dotnetfiddle.net/slm90h
string html = "";
html += Environment.NewLine;
html += Environment.NewLine;
html += Environment.NewLine;
html += Environment.NewLine;
html += Environment.NewLine;
html.Replace(Environment.NewLine, "<br />");
Console.WriteLine(html);
Console.WriteLine("^---- Doesn't work");
html = html.Replace(Environment.NewLine, "<br />");
Console.WriteLine(html);
Console.WriteLine("^----- Does work");
您是否已將IsBodyHtml設置為true; ?
嘆。 這比我想的要簡單。 無需htmlEncode,因為html位於電子郵件頁面而不是網頁中。 (我認為這很有意義)。 我摘下了所有的Environment.Newline和htmlEncode,然后將其放在html中。
string html = "Please confirm your account by clicking this link: " + "<br /><br />" + message.Body;
html += "<br /><br /><br />";
html += "Or click on and copy the link in your browser.";
這是電子郵件正文中發生的事情(所有中斷都發生了):
請點擊以下鏈接確認您的帳戶:
或者單擊並在瀏覽器中復制鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.