Embedded graphics revisited...

  • Thread starter Thread starter Kristy
  • Start date Start date
K

Kristy

Hi

I use Outlook Redemption to embed graphics into HTML Emails. I have a
problem that I just can't seem to work out how to fix, basically when
I embed a graphic into a new item eveything works fine, however when I
embed an item into an existing item (using GetItemFromID()) the
embedded graphic shows up as an attachment when initially
displayed???? (If I save and close the item or send it and then
reopen it the embedded attachements are hidden in teh attachment list
as expected).

Programmatically closing and reopening the item makes no difference.
I have ensured that PR_ATTACHMENT_HIDDEN is set to 'True' and
PR_ATTACH_CONTENT_ID is set to my graphic. It seems to be some sort
of 'refresh' problem but I am certain that all the items are
deferenced etc?

Any ideas would be much appreciated as I need the embedded attachments
to be hidden when it is created though as it causing confusion with my
customers.

Code sample below:

First, the creation of the existing item....

Private Sub cbbInsertGraphic_Click(ByVal Ctrl As
Office.CommandBarButton, CancelDefault As Boolean)
On Error Resume Next

strItemType = "Insert"

Set golApp = GetObject(, "Outlook.Application")
On Error GoTo 0 'close your error trap
If golApp Is Nothing Then
Err.Clear
'Try and create it
Set golApp = CreateObject("Outlook.Application")
End If

Set objItem = golApp.ActiveInspector.CurrentItem
objItem.Subject = objItem.Subject
objItem.Save

EID2 = objItem.EntryID
objItem.Close olSave
Set objItem = Nothing

Call EmbedGraphic
.....
End Sub

Public Sub EmbedGraphic()

Set golApp = GetObject(, "Outlook.Application")
On Error GoTo 0 'close your error trap
If golApp Is Nothing Then
Err.Clear
'Try and create it
Set golApp = CreateObject("Outlook.Application")
End If
Set objNamespace = Outlook.Application.GetNamespace("MAPI")
objNamespace.Logon "", "", False, False 'Added for Redemption

'create new Outlook MailItem with Letterhead or use existing one

If strItemType = "New" Then
Set MailItem = Outlook.Application.CreateItem(olMailItem)
Else
Set MailItem = objNamespace.GetItemFromID(EID2)
End If

'Add attachment to embed
With MailItem
.Attachments.Add ("C:\Test.jpg")
End With

MailItem.Save

'Set Redemption MailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.item = MailItem

'add attachment
Set attach = sItem.Attachments(intAttachNumber)

'tell Outlook to hide the paperclip icon
PT_BOOLEAN = 11
PR_HIDE_ATTACH = sItem.GetIDsFromNames("{00062008-0000-0000-C000-000000000046}",
&H8514) Or PT_BOOLEAN
sItem.Fields(PR_HIDE_ATTACH) = True

'content type
attach.Fields(&H370E001E) = "image/jpeg"
'Attachment cid
attach.Fields(&H7FFE000B) = True
attach.Fields(&H3712001E) = strCompanyLogo
MailItem.Subject = MailItem.Subject
sItem.Save
EID = sItem.EntryID

'de-reference the old item
Set attach = Nothing
Set MailItem = Nothing
Set sItem = Nothing

'get 'refreshed' item back again
Set MailItem = objNamespace.GetItemFromID(EID)

MailItem.HTMLBody = "<IMG align=" &
FIRMDetails(strQueryLogoType).Alignment & " border=0 hspace=0
src=cid:" & strCompanyLogo & ">" & "<body bgcolor=#FFFFFF>"

End If

MailItem.Display

' clean up
intNumberOfAttachments = "0"
Set sItem = Nothing
Set MailItem = Nothing
objNamespace.Logoff
Set objNamespace = Nothing
Set golApp = Nothing

End Sub
 
Outlook does not see the changes made with anything but OOM or the UI until
the message is completely dereferenced and reopened.
Note that you do not have to add the H3712001E property - add the attachment
using OOM rather than Redemption and use the file name when specifying the
image source ("cid:...") in HTMLBody.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi Dmitry, thanks for replying.

I still can't get it to work when using an existing item? I am adding
the attachments to the MailItem object which is the OOM created
object, and using the graphic name for the cid?

I am sure that everything is getting completely dereferenced as it
works fine on a newly created item. The only difference between the
procedure that works and the one that doesn't is the following line of
code...

A newly created item uses the following and it works as expected...
Set MailItem = Outlook.Application.CreateItem(olMailItem)

The existing item uses GetItemFromID instead, and it doesn't hide the
attachment when initially displayed.
Set MailItem = objNamespace.GetItemFromID(EID2)

Using Outlook Spy I can see that all the properties are set
correctly... however the graphic still shows up as an attachment until
the item is closed and reopened... what am I missing, I don't
understand why it works for one and not the other, the exisitng item
must somehow still be in memory but I just can't see how, I have
dereferenced everything that I've set???? If you have a minute could
you please try and recreate this problem, it may be obvious to you?

Thanks

Kris
 
I can believe that it does not work - I would imagine Outlook looks at the
attachment props to figure out whether it needs to be hidden only once when
the message is being displayed and never rereads the property again. I don't
think there is anything you can do.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top