How does Outlook embed pictures in emails??

S

Siv

Hi,

I have written an application which is used by sales staff when discussing
products with their customers over the phone. It is a database application
that holds detailed information about their products including pictures to
assist the sales staff describe features to the customer. The next step in
development of the app is to have a button when in a particular product
screen that the seller can press which sends the customer an email with the
picture embedded in an HTML format Outlook message. I have got it to work
superbly, the email is constructed by the application and sent to the outbox
ready for send and receive and looks fine. When the mail is sent however, I
find that the picture is replace by a place holder "X" symbol indicating the
picture was not found.

My initial thoughts were that I hadn't got the "Send Pictures from the
Internet" option ticked, but even when it is, the picture is still missing.

When I look at an email sent to me from someone where the picture was
inserted into the body text of the message, the image is not mentioned as a
link in normal "img" style format it looks like this:

<DIV>
<FONT face=Arial size=2>
<SPAN class=866055209-20072005>
<IMG alt=chesham hspace=0 src="cid:866055209@20072005-2abd" align=baseline
border=0>
</SPAN>
</FONT>
</DIV>

Does anyone know how you can do this programmatically as I suspect if I just
copy the above HTML code it won't work as the "cid:866055209@20072005-2abd"
is probably specific to the individual instance of the picture sent to me,
it is clearly constructed using the date (UK format). I really need to
understand how Outlook constructs that code and embeds the picture and
indeed if there is a process I can call programmatically that does the
erquivalent of a user embedding the picture manually.

I currently do the following in code:
I have some declarations at the top of the class module:

Private OApp As Outlook.Application
Private email As Outlook.MailItem
Private oNameSpace As Outlook._NameSpace
Private oOutboxFolder As Outlook.MAPIFolder

Then in the subroutine that hangs off a small form that allows the user to
enter the adressee's email and message subject line I have (removed try
catch block and error checking for simplicity):

Dim EmailAddress, ToAddress, BodyHTML, Salutation As String

EmailAddress = txtEmail.Text
Salutation = txtSalutation.Text

OApp = New Outlook.Application
oNameSpace = OApp.GetNamespace("MAPI")
oNameSpace.Logon("outlook", "", False, False)
oOutboxFolder =
oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)

... here I construct a string called BodyHTML which is just the
HTML code for the message body ..

email = OApp.CreateItem(OlItemType.olMailItem)
email.To = EmailAddress
email.Subject = "Details of the Item you requested."
email.HTMLBody = BodyHTML
email.Send()

I need to find out how to build the HTML string so that the picture is
embedded not left behind on the user's PC.

Thanks for any help.
 
J

Jay B. Harlow [MVP - Outlook]

Siv,
Here is an example (requires CDO or Redemption) to add an embedded image
file to a message.

http://www.outlookcode.com/d/code/htmlimg.htm

Hope this helps
Jay

| Hi,
|
| I have written an application which is used by sales staff when discussing
| products with their customers over the phone. It is a database
application
| that holds detailed information about their products including pictures to
| assist the sales staff describe features to the customer. The next step
in
| development of the app is to have a button when in a particular product
| screen that the seller can press which sends the customer an email with
the
| picture embedded in an HTML format Outlook message. I have got it to work
| superbly, the email is constructed by the application and sent to the
outbox
| ready for send and receive and looks fine. When the mail is sent however,
I
| find that the picture is replace by a place holder "X" symbol indicating
the
| picture was not found.
|
| My initial thoughts were that I hadn't got the "Send Pictures from the
| Internet" option ticked, but even when it is, the picture is still
missing.
|
| When I look at an email sent to me from someone where the picture was
| inserted into the body text of the message, the image is not mentioned as
a
| link in normal "img" style format it looks like this:
|
| <DIV>
| <FONT face=Arial size=2>
| <SPAN class=866055209-20072005>
| <IMG alt=chesham hspace=0 src="cid:866055209@20072005-2abd" align=baseline
| border=0>
| </SPAN>
| </FONT>
| </DIV>
|
| Does anyone know how you can do this programmatically as I suspect if I
just
| copy the above HTML code it won't work as the
"cid:866055209@20072005-2abd"
| is probably specific to the individual instance of the picture sent to me,
| it is clearly constructed using the date (UK format). I really need to
| understand how Outlook constructs that code and embeds the picture and
| indeed if there is a process I can call programmatically that does the
| erquivalent of a user embedding the picture manually.
|
| I currently do the following in code:
| I have some declarations at the top of the class module:
|
| Private OApp As Outlook.Application
| Private email As Outlook.MailItem
| Private oNameSpace As Outlook._NameSpace
| Private oOutboxFolder As Outlook.MAPIFolder
|
| Then in the subroutine that hangs off a small form that allows the user
to
| enter the adressee's email and message subject line I have (removed try
| catch block and error checking for simplicity):
|
| Dim EmailAddress, ToAddress, BodyHTML, Salutation As String
|
| EmailAddress = txtEmail.Text
| Salutation = txtSalutation.Text
|
| OApp = New Outlook.Application
| oNameSpace = OApp.GetNamespace("MAPI")
| oNameSpace.Logon("outlook", "", False, False)
| oOutboxFolder =
| oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
|
| ... here I construct a string called BodyHTML which is just the
| HTML code for the message body ..
|
| email = OApp.CreateItem(OlItemType.olMailItem)
| email.To = EmailAddress
| email.Subject = "Details of the Item you requested."
| email.HTMLBody = BodyHTML
| email.Send()
|
| I need to find out how to build the HTML string so that the picture is
| embedded not left behind on the user's PC.
|
| Thanks for any help.
|
| --
| Siv
| Martley, Near Worcester, UK.
|
|
 
S

Siv

Jay,
Many thanks for this, I will pour over it and see if I can a) get my head
round it and b) implement it. Initial look seems to be exactly what I need.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top