0

Scenario I would like to send iframe with google map. I have been trying to do it, but I found that my mail is not send as HTML at all.

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>

*received mail

<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>

Code

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);
}
zolty13
  • 1,943
  • 3
  • 17
  • 34
  • 1
    Why are you escaping the HTML in your `HtmlBody`? You use `<` so it will simply be rendered as a `<`, not parsed as HTML. – user247702 Aug 16 '18 at 11:46
  • To be honest I have no idea. Code in my product is a bit messy so it is difficult to find out. App use Razor.parse to parse email templates. – zolty13 Aug 16 '18 at 12:00
  • 2
    iframes are not recommended in html emails - https://mailchimp.com/help/limitations-of-html-email/ https://www.campaignmonitor.com/blog/email-marketing/2010/08/do-iframes-work-in-email/ You should use a static map instead - https://developers.google.com/maps/documentation/maps-static/intro – mjwills Aug 16 '18 at 12:42

1 Answers1

1

Solution

The problem was that my resolver change < with &lt; etc. It is enough not to replace signs < > etc with their codes. As mjwills noticed, it is not recommended to use iframe at all:

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

zolty13
  • 1,943
  • 3
  • 17
  • 34