Detecting if attachement is embedded or not

R

Russ Green

I've seen lots of discussion on this but no answers.

I have an addin (VB.NET and VSTO) that strips attachements from emails as
they are sent. Trouble is, I don't want to strip attachement (usually
images) that are within the body of the message. I quite often paste images
from the clipboard into my HTML messages and these need to be retained.

So when looping through the attachments in a message how can you robustly
check if the attachment is embedded or not?

Based on other articles I've seen I thought something like this might work
by actually oAttachments.Type doesn't seem to be any different between an
attached XLS file and an embedded JPG file.

Private Function HasNonEmbeddedAttachements() As Boolean
Dim retval As Boolean = False
Dim oAttachment As Outlook.Attachment

If m_olMailItem.Attachments.Count = 0 Then
retval = False
Else
For Each oAttachment In m_olMailItem.Attachments
If oAttachment.Type = Outlook.OlAttachmentType.olByValue
Then
retval = False
Else
retval = True
Exit For
End If
Next
End If

Return retval
End Function
 
R

Russ Green

May have found a simple way.....seems to work at least but will test for a
while first

Private Function HasNonEmbeddedAttachements() As Boolean
Dim retval As Boolean = False
Dim oAttachment As Outlook.Attachment

If m_olMailItem.Attachments.Count = 0 Then
retval = False
Else
For Each oAttachment In m_olMailItem.Attachments
If m_olMailItem.HTMLBody.ToLower.Contains("cid:" &
oAttachment.FileName) = True Then
retval = False
Else
retval = True
Exit For
End If
Next
End If

Return retval
End Function
 

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