Html 邮件不起作用

Html mail does not work

场景 我想发送带有 google 地图的 iframe。我一直在尝试这样做,但我发现我的邮件根本不是按 HTML 发送的。

HtmlBody

<p>&lt;iframe src=\"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d80106.40796404252!2d16.840744817766343!3d51.13935304292101!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x4d72b9e9e002427b!2sStudio+PLAN!5e0!3m2!1spl!2spl!4v1534413878645\" width=\"600\" height=\"450\" frameborder=\"0\" style=\"border:0\" allowfullscreen&gt;&lt;/iframe&gt;</p>

*收到邮件

<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d80106.40796404252!2d16.840744817766343!3d51.13935304292101!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x4d72b9e9e002427b!2sStudio+PLAN!5e0!3m2!1spl!2spl!4v1534413878645" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

代码

try
{
    SmtpMail oMail = new SmtpMail(_eaSendMailLicence);
    SmtpClient oSmtp = new SmtpClient();

    oMail.To = new AddressCollection(email.Receiver);
    oMail.From = new MailAddress(senderConfiguration.SenderName,senderConfiguration.Email);
    oMail.Subject = subject;
    oMail.HtmlBody = htmlBody;
    //oMail.TextBody = textBody;
    oMail.Charset = "utf-8";
    SmtpServer oServer = new SmtpServer(senderConfiguration.SmtpHost, senderConfiguration.SmtpPort);
    oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
    oServer.User = senderConfiguration.Username;
    oServer.Password = GetPlainPassword(senderConfiguration.Password);
    oSmtp.SendMail(oServer, oMail);
}

解决方案

问题是我的解析器将 < 更改为 &lt; 等。 不要用它们的代码替换符号 < > 等就足够了。 正如 mjwills 注意到的,根本不建议使用 iframe:

iframes are not recommended in html emails - mailchimp.com/help/limitations-of-html-email campaignmonitor.com/blog/email-marketing/2010/08/… You should use a static map instead - developers.google.com/maps/documentation/maps-static/intro – mjwills 20 hours ago