Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET IFrame Emai
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.
    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.
 
         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 29-Sep-12 4:13am
Rate this: bad
good
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,
Ed
  Permalink  
Comments
Maciej Los at 29-Sep-12 9:28am
   
Agree, my 5!
Ed Nutting at 29-Sep-12 9:33am
   
Thank you! :)
Marcus Kramer at 29-Sep-12 9:33am
   
My 5.
Espen Harlinn at 29-Sep-12 12:27pm
   
Good point :-D
Ed Nutting at 29-Sep-12 12:31pm
   
Thank you :)
Rate this: bad
good
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="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)
<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>
  Permalink  
Comments
Maciej Los at 29-Sep-12 9:29am
   
Interesting idea, +5!
Ed Nutting at 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
Marcus Kramer at 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 at 29-Sep-12 12:28pm
   
5'ed!
Marcus Kramer at 29-Sep-12 13:42pm
   
Thanks Espen
Rate this: bad
good
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.
 
http://www.felgall.com/noiframe.htm[^]
  Permalink  
Comments
Ed Nutting at 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.
Marcus Kramer at 29-Sep-12 9:32am
   
Absolutely agree with you, Ed. My answer provides the method that youtube implements via their share feature.
Ed Nutting at 29-Sep-12 9:34am
   
Thank you :)

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



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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