Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problems with embedding images in system.net.mail.mailmessage

Problems with embedding images in system.net.mail.mailmessage

Scheduled Pinned Locked Moved C#
csharphtmlquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    livez
    wrote on last edited by
    #1

    Hello! Some of the images I try to embedd do not show up in my email, but are instead sent as attachments. I can´t figure out why some are working and some arent. This is how I embedd images: MailMessage mail = new MailMessage(); string imagePath = System.Windows.Forms.Application.StartupPath + "\\pathToImages"; LinkedResource resource1 = new LinkedResource(imagePath + "\\head21.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg); resource1.ContentId = "head21.jpg"; LinkedResource resource2 = new LinkedResource(imagePath + "\\border.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg); resource2.ContentId = "border.jpg"; StringBuilder content = new StringBuilder(); .... content.Append(string.Format("<td width=600 align=left><img border=0 align=center src=\"cid:head21.jpg\" width=600 height=57></td></tr></tbody></table></td></tr></tbody></table>")); .. content.Append(string.Format("<td><img alt=\"\" src=\"cid:border.jpg\" width=560 height=21></td></tr></tbody></table></td>")); .. string body = Mail.CreateHtmlFromTemplate(content.ToString(), string.Empty, null); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); htmlView.LinkedResources.Add(resource1); htmlView.LinkedResources.Add(resource2); Here resource1 works fine, and shows up in body of email. Resource2 is instead sent as attachment and does not show up in the email. Does anyone have any idea why this is?

    M 1 Reply Last reply
    0
    • L livez

      Hello! Some of the images I try to embedd do not show up in my email, but are instead sent as attachments. I can´t figure out why some are working and some arent. This is how I embedd images: MailMessage mail = new MailMessage(); string imagePath = System.Windows.Forms.Application.StartupPath + "\\pathToImages"; LinkedResource resource1 = new LinkedResource(imagePath + "\\head21.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg); resource1.ContentId = "head21.jpg"; LinkedResource resource2 = new LinkedResource(imagePath + "\\border.jpg", System.Net.Mime.MediaTypeNames.Image.Jpeg); resource2.ContentId = "border.jpg"; StringBuilder content = new StringBuilder(); .... content.Append(string.Format("<td width=600 align=left><img border=0 align=center src=\"cid:head21.jpg\" width=600 height=57></td></tr></tbody></table></td></tr></tbody></table>")); .. content.Append(string.Format("<td><img alt=\"\" src=\"cid:border.jpg\" width=560 height=21></td></tr></tbody></table></td>")); .. string body = Mail.CreateHtmlFromTemplate(content.ToString(), string.Empty, null); AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); htmlView.LinkedResources.Add(resource1); htmlView.LinkedResources.Add(resource2); Here resource1 works fine, and shows up in body of email. Resource2 is instead sent as attachment and does not show up in the email. Does anyone have any idea why this is?

      M Offline
      M Offline
      mustang86
      wrote on last edited by
      #2

      Neat, you can do that? :) My guess is that it may have something to do with the html? How about if you don't do any of the table stuff, and just put the images inline? Does that work?? I've always found coding tables in HTML as tricky. It's easy to miss something. And, depending on the browser, the browser may or may not "fix" some html coding errors. __________ Joe

      L 1 Reply Last reply
      0
      • M mustang86

        Neat, you can do that? :) My guess is that it may have something to do with the html? How about if you don't do any of the table stuff, and just put the images inline? Does that work?? I've always found coding tables in HTML as tricky. It's easy to miss something. And, depending on the browser, the browser may or may not "fix" some html coding errors. __________ Joe

        L Offline
        L Offline
        livez
        wrote on last edited by
        #3

        Thanks for your response! I tried just having the faulty image in a div instead, but it didn´t work :( EDIT: My mistake u were absolutely right. There wasnt enough room for the image, thats why it was sent as an attachment. Thanks alot!

        modified on Tuesday, August 18, 2009 4:37 AM

        M 1 Reply Last reply
        0
        • L livez

          Thanks for your response! I tried just having the faulty image in a div instead, but it didn´t work :( EDIT: My mistake u were absolutely right. There wasnt enough room for the image, thats why it was sent as an attachment. Thanks alot!

          modified on Tuesday, August 18, 2009 4:37 AM

          M Offline
          M Offline
          mustang86
          wrote on last edited by
          #4

          Cool! I'm glad that you found the problem! :) I've always found tables to be a pain in HTML. ___________ Joe

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups