Embedding images in oulook email html body

J

Jesper

Hi

I like to embed a picture in an email. I must not look like an attachment. The body will be html format. I can be done with ordinary use of outlook, but how can I make the same task with use of outlooks automation (com) interface??

I hava allready maked an email item, and set the htmlbody. In the html body where I like to have my image shown, know that I must make a img tag with CID as image source. But I can't find any way to embed the image, and set the cid. I can attach it, but that is not my wish.

My outlook version is 2003, but I prefer if it works with 2000 also.

Can someone please helm me answer this??

Until I went from 2000 I made this with use of setting the body property with a RTF document containing the picture, but in 2003 RTF is no longer rendered.. Why??

Jesper
 
P

Peter Huang

Hi Jesper,

I think you may try to take a look at the links below.
PRB: Cannot Embed Images in Outlook HTML Messages (270922)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;270922

OL2000: Microsoft Does Not Support Setting the "Body" Property to Rich Text
Format (312168)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;312168

As a workaround, I think you may try the approach below to embed the image.
Sub Test()
Dim myMailItem As MailItem
Set myMailItem = Application.CreateItem(olMailItem)
With myMailItem
.To = "(e-mail address removed)"
.Subject = "test"
.HTMLBody = "<IMG src=""Dollar.gif"">" & "dfdf"
.Attachments.Add "c:\Test\TestPIC\Dollar.gif", olByValue
' IMPORTANT: You need to do this to get the e-mail formatted
correctly
Set oInspector = .GetInspector
.Send
End With
End Sub


You may have a try and let me known the result.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jesper

Hi Peter.

Thanks for the fast response.

Your workaround looks like having the same viewing result for the reciever, as if the images was embedding normaly, at least for those reading the mail with outlook.

But another issue here is the users of my system. They are a little concerned about the workaround, because the email they send don't look like as it would have with normally embedding. Further more I told them, that I cant ganrantie that the result will be the same on the different mail readers, that the recievers has. So Result wiil properbly be that we don't use the workaround.

Another solution could be still send the mail in RTF format, but since outlook don't accept RTF in body property, that can't be done, except if automation provides another way of making RTF formatted emails. Can you answer that??

Kind regards
Jesper
 
P

Peter Huang

Hi

If you want to create a mail message with an embedded picture from Outlook
that will be visible on other mail clients.
I think the code sample will work, because once the message is created and
sent from Outlook the message and picture should be visible on any mail
client that supports HTML. And HTML support in 3rd party mail programs is
more common than support for RTF.


If you do not wish to use the Outlook Object Model, then you need to find a
messaging object model that is available on the client machines that you
are using. CDOSYS would most likely be the best object model for this if
Outlook is not available and the machines are Windows XP, Windows 2000, or
newer.

Here is a sample:
'---------------------------------------------------------------------------
-------
Sub SendCDOSYSMessageWithImage()
' TODO: Change the following values to match your configuration

SMTPServerName = "SMTPSERVER"
TOAddress = "(e-mail address removed)"
FROMAddress = "(e-mail address removed)"
SubjectText = "Test Message With Image From CDOSYS"
sFileName = "Test.gif"
sFilePath = "C:\" & sFileName

' Send by connecting to port 25 of the SMTP server.
Dim iMsg As CDO.Message
Dim iConf As CDO.Configuration
Dim Flds
Dim strHTML

Const cdoSendUsingPort = 2

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
SMTPServerName

.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
) = 10
.Update
End With

' Apply the settings to the message.
With iMsg
Set .Configuration = iConf
.To = TOAddress
.From = FROMAddress
.Subject = SubjectText
.AddRelatedBodyPart sFilePath, sFileName, cdoRefTypeId
.HTMLBody = "<IMG src=""" & sFileName & """>"
.Send
End With

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jesper

Hi Peter

The point you have about HTML is wider suported that RTF is a real good argument.
Composing email like yoiu now suggest is not an alternative. The system (CMS) is only composing a kind of templace for the user. Is is the users responsibillity to compose the email finish. The email is a notifycation for something new on the web, and the cms is generation the email, adding the brand for the specific newstype, insertting main title and subtitles, inserting the url for read the information and at last it insert url the reciever can use to change what he/she like to recieve in the future. The composed email is displayed in outlook, and it's now the information composers resposibillity to verify and make the last finish to the email and press the send botton.

An alternative could be using CDO (mapi to exchange) to generate the email, save it, andisplay it in outlook.
Any code examples on that??

Thank you very much.
 
P

Peter Huang

Hi

If you want to send the mail using outlook, why not use the outlook Object
modal directly?
Here is the article about the different between the outlook OM and the
cdosys.dll.
Generally speaking, one is the MAPI based (CDO.dll) while the other is smtp
based(cdonts)

INFO: Differences Between CDO, Simple MAPI, and Extended MAPI
http://support.microsoft.com/default.aspx?scid=KB;EN-US;200018


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jesper

Hi Peter

If the outlook object model doesn't satisfy my needs, I can't used that directly.
But thanks to you, I am in much better position to complete the solution. Thank you very much for the help.

Kind regards
Jesper
 
P

Peter Huang

Hi Jesper,

I am glad that my suggestion helps you.
If you still have any concern on this issue, feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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