Click here to Skip to main content
13,096,157 members (52,163 online)
Rate this:
Please Sign up or sign in to vote.
I need to send a html file(which contains a iframe) inside a email body.The html file is working fine in a browser and playing a video.But when i send it inside email body,iframe tag is not getting interpreted so does not show in the body.
This is html file.
<iframe height="390" frameborder="0" width="640"
title="YouTube video player"></iframe>

Email body only displaying a "Aman" in bold.This is C# code.

StreamReader reader = File.OpenText("C:\\Users\\Girish\\Desktop\\amrit\\Jeff_Project\\indeex.html");
   string getemail = textbox_email.Text;
   System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
   message.Subject = "Hello";
   message.From = new System.Net.Mail.MailAddress("sendingemail");
   //message.Body = "This is message body";
   message.IsBodyHtml = true;
   message.Body = reader.ReadToEnd();
   System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("");
   smtp.Credentials = new System.Net.NetworkCredential("sendingemail", "password");
   smtp.EnableSsl = true;

Why iframe is not being interpret?Am i missing anything?

Please help and provide solutions.

Thanks in advance.
Posted 29-Sep-12 3:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi there,

If you are viewing the email in any decent email client then it will block the use of iFrames unless the suer specifically allows it. Sending HTML emails (especially ones with JavaScript and iFrames) is a very bad idea. 2 reasons: 1) It's unfriendly to users and a common thing for phishing scams or viruses to do. 2) Because of 1, most email clients block JavaScript and iFrames etc so your email will almost never display properly.

Assuming you are trying to publicise your video or whatever: Far better would be to send a snapshot (single frame image) of the webpage or video, a description of it and a text link (NOT an html clickable link) to the page/video. This is friendlier to users, looks less malicious and will display properly across mail clients.

Hope this helps,
Maciej Los 29-Sep-12 9:28am
Agree, my 5!
Ed Nutting 29-Sep-12 9:33am
Thank you! :)
Marcus Kramer 29-Sep-12 9:33am
My 5.
Espen Harlinn 29-Sep-12 12:27pm
Good point :-D
Ed Nutting 29-Sep-12 12:31pm
Thank you :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Your answer is that the use of an iframe in an email message is not well supported.
See this[^] as a reference.

This is also not the correct way to embed a youtube video in email. If you go to youtube and share a video via email with yourself you can inspect the html content of that email to discover how you should embed the video properly.

A static-clickable image that will redirect the user back to youtube.
<a href="">
   <img src="" height="274" width="498">

A playable video(requires flash player)
<embed width="640" height="385" base="" wmode="opaque" id="swfContainer0" type="application/x-shockwave-flash" src="">
Maciej Los 29-Sep-12 9:29am
Interesting idea, +5!
Ed Nutting 29-Sep-12 9:32am
My vote of 4: Not sure I entirely like the idea of hiding the link round an image but at least you recommend using YouTube's standard (I don't think we should be sending HTML emails really - they are just too insecure at the moment!). I certainly wouldn't recommend embedding Flash Player (though Flash is dying now so that bit will be broken inside the next few years I imagine). Please see my solution :)

Marcus Kramer 29-Sep-12 9:34am
I agree, but unfortunately just about anything we could suggest could be mutated into something malicious. Cheers and thanks.
Espen Harlinn 29-Sep-12 12:28pm
Marcus Kramer 29-Sep-12 13:42pm
Thanks Espen
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Your code seems fine,probably the HTML viewer in the mail is not able to support the iframe tag. Use object tag instead.[^]
Ed Nutting 29-Sep-12 9:22am
My vote of 3: Never embed object tags, applets, active-x controls, JavaScript or iFrames in an email - it's far too often malicious content and if it isn't you should avoid being classed as malicious. Please see my solution.


Edit: Also, that solution is unlikely to work across email clients - it's talking about IE6 & 7! Very outdated... A lot of people now use web mail clients such as gmail, which I would hope blocks all types of embedded content such as this - it certainly blocks a lot of embedded files/images which is good - protects the user from malicious content. Furthermore, you would have to start catering for all the browsers and email clients in your one email - much better to simplify the problem and make it friendlier to users by sending description, an image and the url to go to if they trust your email.
Marcus Kramer 29-Sep-12 9:32am
Absolutely agree with you, Ed. My answer provides the method that youtube implements via their share feature.
Ed Nutting 29-Sep-12 9:34am
Thank you :)
kirankumar085 1-Feb-16 9:07am
kirankumar085 1-Feb-16 9:08am
if we are using object tag also it was not displaying in the outlook 2007

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100