Solved

Embed an image from a database into an outlook email

Posted on 2011-02-22
5
975 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

726 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