Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Embed an image from a database into an outlook email

Posted on 2011-02-22
5
Medium Priority
?
988 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 1400 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 600 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

877 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