Solved

Embed an image from a database into an outlook email

Posted on 2011-02-22
5
980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
rogerard earned 350 total points
ID: 34960860
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 43

Assisted Solution

by:Rob
Rob earned 150 total points
ID: 34965569
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
ID: 34975210
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 43

Expert Comment

by:Rob
ID: 34976739
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
ID: 34993371
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
Suggested Courses

623 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