Solved

Embed an image from a database into an outlook email

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

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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 42

Expert Comment

by:Rob Jurd, EE MVE
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 41
Help with Syntax 9 28
html input type 3 22
help squeezing some space out in this site 9 16
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

16 Experts available now in Live!

Get 1:1 Help Now