Solved

Embed an image from a database into an outlook email

Posted on 2011-02-22
5
964 Views
Last Modified: 2012-05-11
Hi there,

I have been looking for quite some time on how to embed images(header and footer) into an outlook email from within a windows application.

The application sends out letters and it need to put the header image(our logo) at the top, then the body of the letter and then our affilliates logos(as one image) at the bottom.  The logos are stored in a sql database(image type) and the letter is in html format.  I had started out by creating a html page as a template and then using that to put the images into and then using .body={html page} but i cannot seem to get it working.  The images just simply come up as little red boxes with a cross.

Any help on this would be much appreciated as I have trying for over a week to try and code this in.

Darren
0
Comment
Question by:chimp153
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
rogerard earned 350 total points
Comment Utility
There are a couple different ways to do what you're asking (add inline/embedded images into html e-mail).  If you are wanting to use the outlook libraries, then the code on this page demonstrates how to do so using that method.
 
Option Explicit
'Add reference to MS Outlook x.x Object Library
'Picture to be added as an attachment and modified src location for each embedded picture.
Private Sub Command1_Click()

  Dim oApp As Outlook.Application
  Dim oEmail As MailItem
  Dim colAttach As Outlook.Attachments
  Dim oAttach As Outlook.Attachment
         
  'create new Outlook MailItem'
  Set oApp = CreateObject("Outlook.Application")
  Set oEmail = oApp.CreateItem(olMailItem)
  'add graphic as attachment to Outlook message'
  'change path to graphic as needed'
  Set colAttach = oEmail.Attachments
  Set oAttach = colAttach.Add("D:\my documents\[color=red]MyPic.jpg[/color]")
  oEmail.Close olSave
  'change the src property to "cid:your picture filename"'
  'it will be changed to the correct cid when its sent.'
  oEmail.HTMLBody = "<BODY><FONT face=Arial color=#000080 size=2></FONT>" & _
  "<IMG alt='' hspace=0 src='[color=red]cid:MyPic.jpg[/color]' align=baseline border=0>&nbsp;</BODY>"
  oEmail.Save
  oEmail.Display 'fill in the To, Subject, and Send. Or program it in.'
  Set oEmail = Nothing
  Set colAttach = Nothing
  Set oAttach = Nothing
  Set oApp = Nothing

End Sub

Open in new window

However, a simpler method I think, is the method outlined on this page, which is a much simpler method to accomplish the task.
Sample 1:
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.ImportHtmlBody( "http://google.com", _ 
	ImportHtmlBodyOptions.ImportHttpPictures OR ImportHtmlBodyOptions.ImportCss )

oMail.SaveAs( "c:\google.eml", true )

Open in new window


Sample 2:
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.ImportHtmlBody( "c:\test.htm", _
	ImportHtmlBodyOptions.ImportLocalPictures OR ImportHtmlBodyOptions.ImportCss )

oMail.SaveAs( "c:\test.eml", true )

Open in new window

0
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 150 total points
Comment Utility
Have you thought about putting the images on the web and linking to them from within the html template.  You can still store the image info in the database, just change the location.  that's what we do with our mailouts.
0
 

Author Comment

by:chimp153
Comment Utility
thanks for the info guys.  I will have a look over the next couple of days and see how I go.

Tagit, will linking them allow them to come up in the email or is it usually blocked until you click to download pictures.  I was thinking that by embedding the images it will come up with the email and they wont have to click to download the image as it is the header and footer of our company letterhead.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
Comment Utility
sure i know what you're saying but it's "6 of one... 1/2 dozen of the other" meaning there's other issues such as people that view their email in plain text.  embedding the image doesn't guarantee it will appear either as some mail programs will remove the images and put them as attachments.

Yes the user would need to click download pictures, but I also provide an online version of my email so that they can click on the link and view it how it SHOULD look, in a browser.
0
 

Author Closing Comment

by:chimp153
Comment Utility
thanks guys.  The pictures as an attachment seems to work fine and will keep in mind the referencing the pictures on the website for the future maybe.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now