Author |
|
oblivionsy Newbie
Joined: 01 November 2007
Online Status: Offline Posts: 4
|
Posted: 01 November 2007 at 7:36am | IP Logged
|
|
|
I want to extract embedded images from the emails and save them as files to disk. I'd also like to have a threshold size limit so any image under 2k for example is ignored. Please can you tell me how to achieve this?
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 01 November 2007 at 8:00am | IP Logged
|
|
|
You should iterate through MailMessage.Attachments collection and check Attachment.Size property of each attachment, then save necessary attachments via Attachment.SaveToFolder method.
Best regards,
Andrew
|
Back to Top |
|
|
oblivionsy Newbie
Joined: 01 November 2007
Online Status: Offline Posts: 4
|
Posted: 01 November 2007 at 8:02am | IP Logged
|
|
|
Are the embedded emails (ie html inline images) included in the attachment collection?
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 01 November 2007 at 8:06am | IP Logged
|
|
|
Yes, Attachment.IsInline property allows you to learn if the attachment is inline.
Best regards,
Andrew
|
Back to Top |
|
|
oblivionsy Newbie
Joined: 01 November 2007
Online Status: Offline Posts: 4
|
Posted: 07 November 2007 at 4:13am | IP Logged
|
|
|
Just following up on this - i have extracted the inline attachments and all works. A comment has been raised though which I wonder if you can help answer.
If my email says:
"please see this image
<image 1 embedded>
and it should be like
<image 2 embedded>
etc"
now the order of the images is important with the contextual part of the text. Is there any way to have some markers as to which image came from where? shout if that didn't make sense. Thanks!
|
Back to Top |
|
|
Andrew AfterLogic Support
Joined: 28 April 2006 Location: United States
Online Status: Offline Posts: 1189
|
Posted: 07 November 2007 at 5:54am | IP Logged
|
|
|
If attachments order is important for you, you may save attachments via Attachment.Save method and assign names with an index, like img01.jpg, img02.jpg, etc.
Also, please take a look at MailMessage.SaveHtmlAndRelatedFiles and MailMessage.GetHtmlAndSaveRelatedFiles methods, perhaps they'll be useful for you.
Best regards,
Andrew
|
Back to Top |
|
|
oblivionsy Newbie
Joined: 01 November 2007
Online Status: Offline Posts: 4
|
Posted: 07 November 2007 at 9:21am | IP Logged
|
|
|
the inline images are removed from the body part of the message. I guess although it is helpful havig the (inline) attachments readily available in the attachments collection, I really need to know where they appeared in the actual html body of the email they were embedded in.
so the example might be :
"please see this image
and it should be like
"
then the html body part might be altered to:
"please see this image
#Image01
and it should be like
#Image02 "
so we know precisly where the image came from within the email body. those smiley faces are then saved as normal (called Image01, Image02)
I am not sure how numbering them will help, since it is the original placement with respect to the surrounding text that is important.
Thanks
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 07 November 2007 at 9:34am | IP Logged
|
|
|
If I understood you correctly, you need to know where (in which IMG tag) certain embedded image is referred.
In most cases, embedded images are referred by their Content-ID. Thus, you should search msg.BodyHtmlText for "cid:" + Attachment.ContentID of the given embedded image.
For instance, IMG tag may look like: <IMG SRC="CID:4dh84sw9h"> and AttachmentCollection contains an attachment with ContentID="4dh84sw9h" and Inline=true.
Regards,
Alex
|
Back to Top |
|
|