1
私はASP.Net MVCアプリケーションを持っています。私はHTMLエディタからHTMLコンテンツを送信する必要があります。私はそれに問題があります。mvcで動的HTMLコンテンツを送信するには
これは私のHTMLエディタです:
これは私のコードです:
public void MailMessageHtml(string body, string subject, string from, IEnumerable<string> to)
{
var message = new MailMessage();
message.To.Add(new MailAddress("[email protected]"));
message.From = new MailAddress(_Settings.MailServer.UserName);
message.Subject = subject;
message.IsBodyHtml = true;
var htmlBody = AlternateView.CreateAlternateViewFromString(
body, Encoding.UTF8, "text/html");
message.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(string.Empty, new ContentType("text/plain")));
message.AlternateViews.Add(htmlBody);
using (var smtp = new SmtpClient())
{
var credential = new NetworkCredential
{
UserName = _Settings.MailServer.UserName,
Password = _Settings.MailServer.Password
};
smtp.Credentials = credential;
smtp.Host = _Settings.MailServer.IPAddress;
smtp.Port = _Settings.MailServer.Port;
smtp.EnableSsl = _Settings.MailServer.EnableSSL;
smtp.Send(message);
}
}
が、メールの体内のHTMLコンテンツは、次のように示されている:
をどうすればよいですか?
これほど多くの詳細は、あなたの '問題'は何の説明もありません... –
あなたは全体の機能を表示してくださいできますか?そして、呼び出し部をお願いします。 – SeM
そのプレーンテキストですか? bodyにプレーンテキストを指定すると、htmlをレンダリングしないクライアントで使用されるはずです。 –