HTML邮件不起作用

时间:2018-08-16 11:34:28

标签: c# easendmail

场景 我想将iframe与Google地图一起发送。我一直在尝试这样做,但是我发现我的邮件根本没有作为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);
}

1 个答案:

答案 0 :(得分:1)

解决方案

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

  

不建议在html电子邮件中使用iframe-mailchimp.com/help/limitations-of-html-email campaignmonitor.com/blog/email-marketing/2010/08/…您应该使用静态地图-developers.google.com/maps/documentation/maps-static/intro – 20个小时前的mjwills