【问题标题】:Why is the email sent containing HTML code rather than in HTML form?为什么发送的电子邮件包含 HTML 代码而不是 HTML 格式?
【发布时间】:2017-09-04 19:17:35
【问题描述】:

我正在尝试按如下方式发送 Outlook 电子邮件,我没有看到任何错误或异常,但是当电子邮件发出时它仍然是 HTML 代码,如下所示?我错过了什么?

    public object SendBuildAnnouncementEmail(string softwareProductBuildID)
    {
        try
        {
            MailMessage mail = new MailMessage("fromname@yourmail.com", "toname@yourmail.com");
            SmtpClient client = new SmtpClient();
            client.Port = 25;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Host = "smtphost.company.com";
            mail.Subject = "this is a test email.";
            //mail.Body = "this is my test email body";
            mail.Body = "";
            var output = GetBuildAnnounceDetails(softwareProductBuildID);
            foreach (var item in output)
            {
                mail.Body += "<html>";
                mail.Body += "<p>" + item.SP + "</p>";
                mail.Body += "<p>" + item.CreatedDate + "</p>";
                mail.Body += "<p>" + item.AnnouncedDate + "</p>";
                mail.Body += "<p>" + item.AnnouncedBy + "</p>";
                mail.Body += "</html>";
            }
            //client.Send(mail);
            client.Send(mail);
        }
        catch
        {
            throw;
        }
        return null;
    }

HTML 代码:-

<html><p>spname</p><p>4/8/2017 5:24:37 PM</p><p>4/8/2017 5:43:34 PM</p><p>name</p></html>

【问题讨论】:

  • 尝试添加mail.IsBodyHtml = true;

标签: html asp.net email


【解决方案1】:

为了发送 HTML 格式的电子邮件,添加

mail.IsBodyHtml = true;

到您的代码。 (client.Send(mail);之前)

【讨论】:

  • 没有。虽然包含文档类型总是好的,但 HTML 邮件中不一定需要 &lt;html&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-23
  • 1970-01-01
  • 2010-11-26
  • 2014-06-22
相关资源
最近更新 更多