none
[EWS][C#]:Extract Attachments From Inner Messages using EWS. RRS feed

  • Question

  • Hi,

    I need to download all the attachments from Email using EWS in C#. The challenge is My email will have attachments which are Emails which might have attachments and Email Attachments and so on.. Basically it will be nested to n levels…

    I know how to get to one level but beyond that am not able to get it working..


    • Edited by J_BizTalk Wednesday, August 14, 2013 6:04 PM
    Wednesday, August 14, 2013 5:42 PM

Answers

  • I tried that and that worked but was not confident as am not sure what issues it might cause when dealing with bulk message and High volume

    private void processsubAttachment(ItemAttachment itemAttachment, string strFilePath)
            {
                foreach (Attachment subAttachment in itemAttachment.Item.Attachments)
                {
                    if (subAttachment is FileAttachment && !subAttachment.IsInline)
                    {
                        SaveAttachement(subAttachment, strFilePath);
                    }
                    else if(subAttachment is ItemAttachment)
                    {
                        ItemAttachment _itemAttachment = subAttachment as ItemAttachment;
                        _itemAttachment.Load(ItemSchema.Attachments);
                     processsubAttachment(_itemAttachment, strFilePath);
                        
                        SaveasEML(itemAttachment, strFilePath);
                    }
                }
                SaveasEML(itemAttachment, strFilePath);
            }


    • Edited by J_BizTalk Wednesday, August 14, 2013 7:29 PM
    • Marked as answer by J_BizTalk Friday, August 16, 2013 1:26 PM
    Wednesday, August 14, 2013 7:29 PM

All replies

  • Hi J_Biztalk,

    haven't tried to do something like that, but maybe using recursion could do the trick for that scenario.

    Regards,
    Fred


    There's no place like 127.0.0.1

    Wednesday, August 14, 2013 7:01 PM
  • I tried that and that worked but was not confident as am not sure what issues it might cause when dealing with bulk message and High volume

    private void processsubAttachment(ItemAttachment itemAttachment, string strFilePath)
            {
                foreach (Attachment subAttachment in itemAttachment.Item.Attachments)
                {
                    if (subAttachment is FileAttachment && !subAttachment.IsInline)
                    {
                        SaveAttachement(subAttachment, strFilePath);
                    }
                    else if(subAttachment is ItemAttachment)
                    {
                        ItemAttachment _itemAttachment = subAttachment as ItemAttachment;
                        _itemAttachment.Load(ItemSchema.Attachments);
                     processsubAttachment(_itemAttachment, strFilePath);
                        
                        SaveasEML(itemAttachment, strFilePath);
                    }
                }
                SaveasEML(itemAttachment, strFilePath);
            }


    • Edited by J_BizTalk Wednesday, August 14, 2013 7:29 PM
    • Marked as answer by J_BizTalk Friday, August 16, 2013 1:26 PM
    Wednesday, August 14, 2013 7:29 PM
  • execution speed on EWS is based on a formula like this I think: 2N + M + C +W.
    N is the network transfer overhead (for one direction),
    M is the data size transfered,
    C is the calculation time required by Exchange (will be almost 0 for attachment load requests, a lot more for specific properties, especially on appointments) and
    W is the waiting penalty you accrue for requests on an overloaded (CPU-wise) Exchange.

    as you load each item individually, you'll get a high N cost. The M cost is unaffacted by how you portion it out and C ought to be a non-factor. W is dependant on the load your server is under.

    Causes of failure of execution (beyond connectivity loss) will be IIS timeout and EWS timeout (unless failure to execute in a given time will cause your programm to terminate internally). IIS timeout will only happen if you get an M so big it would have failed anyway, assuming stable network loads. You may need to tune your EWS timeouts to your needs.

    What this whole dissertation comes down to is this:
    Upscaling your application in target scope will extend execution times linearly, but in and of itself it will not cause a failure if precautions against timeouts are taken. Your programm will not affect other access to mail services considerably, unless your network infrastructure is overloaded (In which case you'd have an impact anyway, no matter the load. Extending the duration of execution would extend the duration of impact linearily).

    That's the best estimate I can make on the impact you will have,

    cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, August 14, 2013 7:52 PM
  • Thanks for that brief Explanation ...  i will go ahead with my code ...
    Friday, August 16, 2013 1:26 PM