0

I have the following code which attaches an image to the email but I need this image to be embedded in the html of the email.

Any ideas??

objMM.Attachments.Add(new MailAttachment(Server.MapPath("images1/links/beach-icon.jpg")))

  objMM.Body = "<p>There should be an attachment</p> <img src='beach-icon.jpg' /> <p>with this email</p>"
Tom
  • 12,776
  • 48
  • 145
  • 240

1 Answers1

0

I think this does the job, though it doesn't work in Mail for Mac OSX

Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString("This is my plain text content, viewable by those clients that don't support html", Nothing, "text/plain")

Dim logo As New LinkedResource(Server.MapPath("images1/links/beach-icon.jpg"))

logo.ContentId = "embeddedimage"

Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString("<p>Here is an embedded image.</p> <img src=cid:embeddedimage> <p>More text here</p>", Nothing, "text/html")

htmlView.LinkedResources.Add(logo)

objMM.AlternateViews.Add(plainView)
objMM.AlternateViews.Add(htmlView)
Tom
  • 12,776
  • 48
  • 145
  • 240