Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 我应该如何在C中通过SmtpClient发送的电子邮件中呈现HTML_Asp.net Mvc_Email - Fatal编程技术网

Asp.net mvc 我应该如何在C中通过SmtpClient发送的电子邮件中呈现HTML

Asp.net mvc 我应该如何在C中通过SmtpClient发送的电子邮件中呈现HTML,asp.net-mvc,email,Asp.net Mvc,Email,我想将包含html标记的文本作为电子邮件发送给用户。 我尝试使用HttpUtility.HtmlDecode解码html: 下面是MailService类中的SendEmail: public void SendEmail(string subject, string body, string fromAddress, string fromName, string toAddress, string toName, string replyTo

我想将包含html标记的文本作为电子邮件发送给用户。 我尝试使用HttpUtility.HtmlDecode解码html:

下面是MailService类中的SendEmail:

public void SendEmail(string subject, string body,
            string fromAddress, string fromName, string toAddress, string toName,
            string replyTo = null, string replyToName = null,
            IDictionary<string, string> headers = null)
        {
            var message = new MailMessage();
            //from, to, reply to
            message.From = new MailAddress(fromAddress, fromName);
            message.To.Add(new MailAddress(toAddress, toName));
            if (!String.IsNullOrEmpty(replyTo))
            {
                message.ReplyToList.Add(new MailAddress(replyTo, replyToName));
            }

            //content
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = true;

            //headers
            if (headers != null)
                foreach (var header in headers)
                {
                       message.Headers.Add(header.Key, header.Value);
                }

            try
            {
                var client = new SmtpClient("mail.myserver.com", 25)
                {
            Credentials = new NetworkCredential("info@myserver.com", "myEmailPassword"),
            EnableSsl = false
                };
                client.Send(message);

                //send email
            }
            catch (Exception exc)
            {

             logger.Error(exc.Message);

            }
        }  
但是我的用户收到一封带有简单html标记代码的电子邮件。
如何将html文本作为呈现在用户邮箱中的电子邮件发送?

以下是我如何使用Postal从控制器发送电子邮件:

EmailTemplateModel:

public class EmailTemplateModel : Email
{
    public string FromAddress { get; set; }
    public string EmailAddress { get; set; }
    public string Subject { get; set; }
    public string Description { get; set; }
    public DateTime SingleDate { get; set; }
}
我使用此模板创建电子邮件的HTML元素:

@model App.Models.EmailTemplateModel
@using App.Utilities;

From: @Model.FromAddress
To: @Model.EmailAddress
Subject : @Model.Subject

<table style="width: 500px;">
    <tbody>
        <tr>
            <td>
                Date:
            </td>
            <td>
                @Model.SingleDate
            </td>
        </tr>
        <tr>
            <td>
                Description:
            </td>
            <td>
                @Model.Description
            </td>
        </tr> 
    </tbody>
</table>
public class EmailTemplateModel : Email
{
    public string FromAddress { get; set; }
    public string EmailAddress { get; set; }
    public string Subject { get; set; }
    public string Description { get; set; }
    public DateTime SingleDate { get; set; }
}
@model App.Models.EmailTemplateModel
@using App.Utilities;

From: @Model.FromAddress
To: @Model.EmailAddress
Subject : @Model.Subject

<table style="width: 500px;">
    <tbody>
        <tr>
            <td>
                Date:
            </td>
            <td>
                @Model.SingleDate
            </td>
        </tr>
        <tr>
            <td>
                Description:
            </td>
            <td>
                @Model.Description
            </td>
        </tr> 
    </tbody>
</table>