2016-10-26 3 views
1

私はASP.Net MVCアプリケーションを持っています。私はHTMLエディタからHTMLコンテンツを送信する必要があります。私はそれに問題があります。mvcで動的HTMLコンテンツを送信するには

これは私のHTMLエディタです:

enter image description here

これは私のコードです:

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コンテンツは、次のように示されている:

enter image description here

どうすればよいですか?

+0

これほど多くの詳細は、あなたの '問題'は何の説明もありません... –

+0

あなたは全体の機能を表示してくださいできますか?そして、呼び出し部をお願いします。 – SeM

+0

そのプレーンテキストですか? bodyにプレーンテキストを指定すると、htmlをレンダリングしないクライアントで使用されるはずです。 –

答えて

1

コンテンツをボディに渡す前に、コンテンツをデコードする必要があります。

body = HttpUtility.HtmlDecode(body); 

これだけです。

関連する問題