| Code level: advanced Code area: Outlook Expert Techniques Printer Friendly Version | ||
| Title: Distinguishing embedded attachments | ||
| Description: Using Redemption to work with the Attachment.Fields collection, we can determine whether a particular attachment is embedded in the message by getting its content ID. That ID can also be used to match up the attachment with particular src attributes in the body of an HTML message. (Similar code could be built with CDO instead of Redemption.) | ||
| Date: 07-Jan-2003 13:47 | ||
| Code level: advanced | ||
| Code area: Outlook Expert Techniques | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 17comments |
| Page [ 1 2 Next >> ] | ||
|
|
Sue Mosher
07-Jan-2003 22:25
See http://www.outlookcode.com/codedetail.aspx?id=27 for the other side of this issue -- creating a message that includes an embedded image attachment. |
|
|
|
Dave Carroll
28-Feb-2003 17:14
This does not always work. For some reason, I was viewing an email that was had like 19 attachments reported by Redemption and Outlook OM, but none of the "attachments" had CIDs. The email was almost pure HTML and there were in fact no attachments. On the other hand, if a message has an attachment, it will definitely be represented in the MIME header. So you grab the mime header and parse it into sections, inspecting each section for key value pairs such as: Content-Disposition: attachment; The section that contains this pair is below: ------_=_NextPart_002_01C2DF6A.922C985E-- ------_=_NextPart_001_01C2DF6A.922C985E Content-Type: image/gif; name="loginbtn.gif" Content-Transfer-Encoding: base64 Content-Description: loginbtn.gif Content-Disposition: attachment; filename="loginbtn.gif" It is clear that this is infact explicitly an attachment. I'm always leery of logic that depends on a missing value such as the lack of a CID, not all mail systems use it I guess. |
|
|
|
Dave Carroll
28-Feb-2003 19:02
Sue had it just about right. Forget the mime header junk. Use the content id and the PR_ATTACH_FLAGS properties together. |
|
|
|
Joost van der Nat
14-Jul-2004 11:19
Not much of a programmer myself, but I managed to get this working with CDO: Probably needs some cleaning up, here & there.... Regards, Joost Sub check_CID_with_CDO() Dim itm As Object Dim objSMail As MAPI.Message Dim objSAtt As MAPI.Attachment Dim obj As Object Dim objSession As MAPI.Session Dim strCID As String On Error Resume Next Set objSession = CreateObject("MAPI.Session") objSession.Logon , , False, False Set itm = GetCurrentItem() If itm.Class = olMail Then Set objSMail = CreateObject("MAPI.Message") strEntryID = itm.EntryID Set oMsg = objSession.GetMessage(strEntryID) For Each objSAtt In oMsg.Attachments ' Get the content-ID for the attachment, ' if present. Thanks to Dmitry Streblechenko, ' author of Redemption, for the proptag. ' x3712001f for RTF ???? strCID = objSAtt.Fields(&H3712001E) If strCID = "" Then MsgBox "Content-id is Empty, so attachment is not embedded..." Else MsgBox "Content-id = " & strCID & _ " So it is embedded..." End If strCID = "" Next End If Set objSAtt = Nothing Set itm = Nothing End Sub Function GetCurrentItem() As Object Dim objApp As Outlook.Application Set objApp = CreateObject("Outlook.Application") On Error Resume Next Select Case TypeName(objApp.ActiveWindow) Case "Explorer" Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) Case "Inspector" Set GetCurrentItem = objApp.ActiveInspector.CurrentItem Case Else ' anything else will result in an error, which is ' why we have the error handler above End Select Set objApp = Nothing End Function |
|
|
|
Jeremy
19-Aug-2004 12:58
So let's say I copy the book logo from this site and past it in the message body of an outgoing message (html format) and use the code at the top of this thread to determine if there are any embedded attachments when the message is sent. The book.gif file is considered "not embedded" because it doesn't have a CID. I'm thinking it should be considered embedded because it's in the body of the email but maybe embedded means an attachment that is actually sent with the email (has a CID). Am I making any sense? I guess what I'm really getting at is: What is an embedded attachment? I was thinking it's a file inside the message body, but am not really sure now. |
|
|
|
Henrik Andre Tellevik
02-Nov-2004 05:16
Could anyone please tell me why this code will not work? I have used the example to attach the graphic but it keeps showing up as an attachment and a red x in the box where the graphic goes. |
|
|
|
Ryan Holder
18-Jul-2006 17:12
Hi Sue I followed the script from the article "Add embedded image to HTML message (VBScript)" and combined it with redemption which I am already using for the Outlook security warning issue. When I embed one image everything works fine and when I send the email the person recieving the email does see any attached files. As soon as I try to embed more than one image I have a problem. The email in the Outlook outbox is fine but when the email is recieved you can now see the files as attachments in the attachments field. The following is the code I used: (From the redemption site) Set sItem = CreateObject("Redemption.SafeMailItem") sItem.Item = Connect.MyMailItem PT_BOOLEAN = 11 PR_HIDE_ATTACH = sItem.GetIDsFromNames("{00062008-0000-0000-C000-000000000046}", &H8514) Or PT_BOOLEAN sItem.Fields(PR_HIDE_ATTACH) = True Set Attach1 = sItem.Attachments.Add("C:\Documents and Settings\Ryan\Application Data\Microsoft\Stationery\Top_01.gif") Attach1.Fields(&H370E001E) = "image/jpeg" Attach1.Fields(&H3712001E) = "img01" Please tell me what I need to do for multiple embedded files. Thanks in advance Ryan |
|
|
|
Ryan Holder
18-Jul-2006 17:33
Hi Sue An update to my post from just now. I have noticed that the problem does not occur unless I have created the mail but before hitting send and recieve I open the mail in the outbox and then click the send button again, it is when I go through this procedure that person recieving the mail can see the attachments. Regards Ryan |
|
|
|
Sue Mosher
21-Jul-2006 16:13
Then, don't do that. The code method is intended to work without any user intervention. If you display the message, you'll get unintended results, as you've learned. Also, I think you may need to set the field on the message *after* you add the attachments and set their properties. |
|
|
|
Avadhesh
05-Jul-2007 00:41
I copy ur code in VBE and restart MS Office outlook 2003 but it is not working. |
|
| Page [ 1 2 Next >> ] | ||
| Post your comment name email |
