Results 1 to 3 of 3

Thread: Including an image in an HTML email

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Including an image in an HTML email

    Hello

    When I use the following (stripped) lines of code to load an image into an SMTP HTML email, the image does not appear in the main window of my inbox (I have tried it using an Outlook email account and Yahoo email account):

    Code:
    Dim mimeType As ContentType = New ContentType("text/html")
           
    Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("<body style=""background:url('cid:dimaHeader') no-repeat;"">'font-family:candara'> To reset your password.....</body>", Nothing, "text/html")
               
    Dim Logo As New LinkedResource(Server.MapPath("~/Images/dimaHeader.jpg"), "image/jpeg") 'embedded image
                
    Logo.ContentId = "dimaHeader"
    
    myMessage.AlternateViews.Add(PlainMessage)
    myMessage.AlternateViews.Add(HtmlMessage)
    The image is stored in Solution Explorer (Visual Studio) as are all the images on the Web site. I am just wondering, have I got this part right?

    Code:
    Dim HtmlMessage As AlternateView = AlternateView.CreateAlternateViewFromString("<body style=""background:url('cid:dimaHeader') no-repeat;"">
    Thank you

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,543

    Re: Including an image in an HTML email

    "~/Images/dimaHeader.jpg" <- that's a relative url ... you need to use an absolute URL: http://webserver/folder/anotherfolder/onemoreforgoodluck/someimage.jpg


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    469

    Re: Including an image in an HTML email

    Thanks tg, I think it's working now!

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width