distinguish between inline images and other attachments in outlook message
- Hi everybody,
I'm writing an outlook plugin manipulating emails attachments.
Now I've a problem with html email, 'cause in the attachments collection I see also the inline images of the message.
Is there away to distinguish between "regular" attachments and inline images?
Tks in advance,
Luigi
Answers
- Hi again Luigi!
This may be a bit of a stretch but how about using regular expressions?
Other than those mentioned already, I can't think of any other way to determine if an attachment is inline.
I also thought about using the Body property of the Outlook.MailItem object but it could also be possible
that the file name of an inline image can be typed into the e-mail*:
Outlook.MailItem mailItem;
Outlook.Attachment attachment = mailItem.Attachments[1];
bool isInline;
if (mailItem.HtmlBody.Contains(attachment.FileName))
{
if (mailItem.Body.Contains(attachment.FileName))
{
// *
}
else
{
isInline = true;
}
}
else
{
isInline = false;
}- Marked As Answer byBessie ZhaoMSFT, ModeratorTuesday, November 10, 2009 2:01 AM
All Replies
Hi Luigi!
If an image attachment is inline, then the file name of that attachment will be present in the e-mail's markup.
See the sample C# code below:
Outlook.MailtItem mailItem;
foreach (Outlook.Attachment attachment in mailItem.Attachments)
{
bool attachmentIsInline = false;
string fileName = attachment.FileName;if (mailItem.HTMLBody.Contains(fileName))
{
attachmentIsInline = true;
}
}- Proposed As Answer byJose Anton Bautista Monday, November 02, 2009 9:52 AM
- Hi Jose,
I already thought of a similar algorithm, but I encountered this use case that makes it fails.
If in the body,for example, is written "I attach the file Image.bmp", the algorithm fails, because "image.bmg" is treated as an online image and not as attachment.
I hope I've been clear
Thanks,
LuigiHi Luigi!
If an image attachment is inline, then the file name of that attachment will be present in the e-mail's markup.
See the sample C# code below:
Outlook.MailtItem mailItem;
foreach (Outlook.Attachment attachment in mailItem.Attachments)
{
bool attachmentIsInline = false;
string fileName = attachment.FileName;if (mailItem.HTMLBody.Contains(fileName))
{
attachmentIsInline = true;
}
} - Hi again Luigi!
Have you tried treating the HTMLBody as an XML and searching for all <img> elements?
The <img> element has a src attribute which you can check if it contains the file name of the attachment.
If it does, the image attachment must be inline. - Hi Jose,
I also tried something similar, but I've been blocked by cid structure
Look at this for example:
<img width=642 height=159 id="Immagine_x0020_1" src="cid:image001.png@01CA385D.FE70A6B0">
- Hi again Luigi!
This may be a bit of a stretch but how about using regular expressions?
Other than those mentioned already, I can't think of any other way to determine if an attachment is inline.
I also thought about using the Body property of the Outlook.MailItem object but it could also be possible
that the file name of an inline image can be typed into the e-mail*:
Outlook.MailItem mailItem;
Outlook.Attachment attachment = mailItem.Attachments[1];
bool isInline;
if (mailItem.HtmlBody.Contains(attachment.FileName))
{
if (mailItem.Body.Contains(attachment.FileName))
{
// *
}
else
{
isInline = true;
}
}
else
{
isInline = false;
}- Marked As Answer byBessie ZhaoMSFT, ModeratorTuesday, November 10, 2009 2:01 AM


