Attachments And Embedded Images

  • Thread starter Thread starter Tyler
  • Start date Start date
T

Tyler

Sorry if this question displays twice, it gave me an internal server
error.

I am having some success with Attachments and images embedded in the
message but am not having any luck when both are used in one message.
How do I determine what type of attachment it is (embedded or a file)?
I have tried using the Fields(&H3712001E) to see if it has a cid but
can't get that to work and the type property of the attachment is
always 1.

set fso = CreateObject("Scripting.FileSystemObject")
set fldTemp = fso.GetSpecialFolder(2)
strPath = fldTemp.Path & "\"

For i = 1 To objAttachments.Count
strFile = strPath & objAttachments(i).FileName
objAttachments(i).SaveAsFile strFile
set Attach = SafeItem.Attachments.Add(strFile, , ,
objAttachments(i).DisplayName)
Attach.Fields(&H370E001E) = "image/jpeg"
Attach.Fields(&H3712001E) = "myidnet"
SafeItem.HTMLBody = REPLACE(SafeItem.HTMLBody,
MID(SafeItem.HTMLBody, Instr(SafeItem.HTMLBody, "cid:"), 27),
"cid:myidnet")
fso.DeleteFile strFile
Next

This code works when I only have one embedded image and no
attachments, it delivers the message with the embedded image not an
attachment. Is it possible to have more than one embedded image in a
message? The attachment count returns a 1 for the attachment count if
more than one, so not sure if it is possible.
 
1. How do you know that the cid length is equal to 27?
2. You are replacing cid of *all* embedded messages with the same cid.
3. Why do you save the attachments then immediately add the same attachments
ending up with twice as many attachments?

I am not sure I understand what you are trying to do.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
The code at http://www.outlookcode.com/codedetail.aspx?id=52 shows how to use Redemption to check whether a CID exists for the attachment. If there is no CID, you know it's not embedded.

One problem with your code below is that it reuses the same CID for each attachment, when it should be using a unique ID for each one.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
1. I don't know that the cid length is always going to be 27. I was just
using that number for testing. I tried using INSTR(SafeItem.HTMLBody,
CHR(34)) as the last part of the MID function to determine the end of
the cid but it was cutting the cid off before the " which is the end of
the id.

2. I know I will need to modify the replacement of the cid. I can do
this by looping through the attachments and appending the count to the
end of the string, problem is I am only getting a count of 1 no matter
how many embedded images I have in the message.

3. I am looping through a table to create mail messages and all the
messages need the attachments in them. I don't get double the
attachments in the messages.

I am trying to keep the attachments as attachments in the message which
hasn't been a problem. The problem is getting the embedded images to
stay as part of the message and not changing to attachments. Hope that
clarifies a little and thanks for the quick response.
 
So essentially you want to hide attachments used as images in the HTML body
but leave other attachments accessible to users? Note that in both cases
images stay as attachments, it is just Outlook hides some attachments from
the user UI
To make an attachment invisible to a user, all you really need to do is set
a property on the attachment - PR_ATTACHMENT_HIDDEN (0x7FFE000B).
PR_ATTACH_CONTENT_ID does the same thing - attachments with that property
set are not accessible through the UI.
To hide the paperclip icon from the messages list, set a named property on
the message - GUID is {00062008-0000-0000-C000-000000000046} and id=0x8514,
type PT_BOOLEAN, value must be boolean true.

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

No matter how many embedded images I have in a message the form always
returns a count of 1 for the images. How do I replace the CID properly
if it only returns 1? How do I get the correct count?

' this only counts the images as 1 attachment
For Each objSAtt In SafeItem.Attachments

strCID = objSAtt.Fields(&H3712001E)
msgbox strCID
Next

I want the delivered message to look like the composed message. The
attachments as attachments and the embedded images as images.
 
When I have attachments and embedded images in the email the Attachment
Object returns a type of Nothing. If I have just an attachment or just
an embedded image it returns a type of Attachment. Is it not possible to
have both in one message?

TestItem = CreateObject("Redemption.MailItem")
TestItem = Item
' the typename of the attachments for Item are correct. Seems like the
TestItem = Item doesn't take all objects with it


For Each ObjSAtt In TestItem.Attachments
msgbox TypeName(ObjSAtt)
IF Not TypeName(objSAtt) = "Nothing" Then
i = i + 1
strCID = objSAtt.Fields(&H3712001E)

IF Not IsEmpty(strCID) then

newCID = "myidnet" & cstr(i)

strFile = strPath & objAttachments(i).FileName
objAttachments(i).SaveAsFile strFile
set Attach = SafeItem.Attachments.Add(strFile, , ,
objAttachments(i).DisplayName)
Attach.Fields(&H370E001E) = "image/jpeg"

Attach.Fields(&H3712001E) = newCID
SafeItem.HTMLBody = REPLACE(SafeItem.HTMLBody,
MID(SafeItem.HTMLBody, Instr(SafeItem.HTMLBody, "cid:"), 27), "cid:" &
newCID)
End If
End If
Next
 
Change the line
TestItem = Item
to
TestItem.Item = Item
Your code as is was not using Redemption at all.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I get the attachment count with the following code:

TestItem.Attachments.Count

I do not save the item before getting the count. I added the code
TestItem.Save before the count and it returns the same count.
 
I have changed that, but it didn't solve my problems. Still get a count
of 1 for the embeded images and the Attachment object is of type Nothing
when I have both file attachments and embedded images.

Thanks
 
Back
Top