Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.70/5 (3 votes)
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.
HTML
Aman
<iframe height="390" frameborder="0" width="640"
src="http://www.youtube.com/embed/Sf5T5KjMpJU?wmode=transparent"
title="YouTube video player"></iframe>


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

C#
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.To.Add(getemail);
   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.gmail.com");
   smtp.Credentials = new System.Net.NetworkCredential("sendingemail", "password");
   smtp.EnableSsl = true;
   smtp.Send(message);
   Response.Write("Sent");

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

Please help and provide solutions.

Thanks in advance.
Posted
Updated 25-Jun-18 4:05am

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,
Ed
 
Share this answer
 
Comments
Maciej Los 29-Sep-12 9:28am    
Agree, my 5!
Ed Nutting 29-Sep-12 9:33am    
Thank you! :)
fjdiewornncalwe 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 :)
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.
HTML
<a href="http://www.youtube.com/watch?v=Bk_6r-b3kqU&feature=em-share_video_user">
   style="text-decoration:none;display:block" 
   class="nonplayable" 
   target="_blank">
   <img src="http://i3.ytimg.com/vi/Bk_6r-b3kqU/mqdefault.jpg" height="274" width="498">
</img></a>


A playable video(requires flash player)
HTML
<embed width="640" height="385" base="https://www.youtube.com/v/" wmode="opaque" id="swfContainer0" type="application/x-shockwave-flash" src="https://www.youtube.com/v/Bk_6r-b3kqU?border=0&autoplay=1&client=ytapi-google-gmail&version=3&start=0">
</embed>
 
Share this answer
 
Comments
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 :)

Ed
fjdiewornncalwe 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    
5'ed!
fjdiewornncalwe 29-Sep-12 13:42pm    
Thanks Espen
Your code seems fine,probably the HTML viewer in the mail is not able to support the iframe tag. Use object tag instead.

http://www.felgall.com/noiframe.htm[^]
 
Share this answer
 
Comments
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.

Ed

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.
fjdiewornncalwe 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    
test
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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900