.NET Components for Mobility

Download email attachments

Last post 04-14-2010 5:54 AM by penyaskito. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 03-11-2010 12:27 PM

    Download email attachments

    Hi Pete!
    Is there any way of downloading attachments? In Outlook, when you open a mail and click on an attachment, the attachment is downloaded if the device is connected to the internet or to cradled with the PC.
    Is the any way of copying this behaviour?
    Thanks in advance
    Filed under: , ,
  • 03-11-2010 6:06 PM In reply to

    Re: Download email attachments

    The current version doesn't include this functionality but I've just finished implementing it for v4.1. Basically it works like the current RemoteDownload() method for an EmailMessage - it marks the specific attachment for download. Depending on your account settings you may then need to trigger a Send/Receive with MessagingApplication.Synchronize().

    Peter

    Filed under:
  • 03-18-2010 7:17 AM In reply to

    Re: Download email attachments

    Hi Peter,
    I'm running into problems with this too.
    Here is my piece of code:


    if (!attachment.DownloadState == DownloadState.FullItem)
    {
    attachment.RemoteDownload();
    MessagingApplication.Synchronize();
    }

    BTW, the DownloadState is always HeaderOnly. Because of the other thread we have at http://inthehand.com/forums/t/3364.aspx, I tried to dispose and retrieving again the Attachment like follows: (Feature request: It would be great that attachments become first class citizens if possible: having an ItemId and being able of retrieving them without reference to the EmailMessage. Exposing the EmailMessage property would be great too):

    EmailMessage msg = email.getOriginalMail();
    if (msg.DownloadState != DownloadState.FullItem)
    {
    msg.RemoteDownload();
    MessagingApplication.Synchronize();
    }
    ItemId id = msg.ItemId;
    msg.Dispose();
    msg = new EmailMessage(id);
    for (int i = 0; i
    {
    if (attachment.Name == msg.Attachments[ i ].Name)
    {
    attachment = msg.Attachments[ i ] ;
    attachment.RemoteDownload();
    Item = attachment;
    break;
    }
    }


    But the attachment is always with the HeaderOnly DownloadStatus. Am I doing anything wrong? Could this be a InTheHand bug?
    Thanks, again, for your support.
  • 03-25-2010 1:52 PM In reply to

    Re: Download email attachments

    Hi Peter,
    I have a NullReferenceException every time I try to save an attachment.
    My code is:
    if (attachment.DownloadState == DownloadState.FullItem) attachment.Save("\\TEMP\\" + attachment.Name);
    And the stacktrace:
    at InTheHand.IO.StreamHelper.CopyTo(Stream s, Stream destination, Int32 bufferSize) at InTheHand.IO.StreamHelper.CopyTo(Stream s, Stream destination) at InTheHand.WindowsMobile.PocketOutlook.Attachment.Save(String path)
    This test has been done with an IMAP account and it seems that the attachment is being downloaded correctly (the DownloadState takes a time to be FullItem).
    If you need more details just ask.
  • 04-14-2010 5:54 AM In reply to

    Re: Download email attachments

    Not working for me :/ I'm trying attachment.RemoteDownload(); string name = attachment.Name; MessagingApplication.Synchronize(); and then I get the email where the attachment is attached, and I RemoteDownload it, but it don't works either. email.RemoteDownload(); MessagingApplication.Synchronize(); Any hint?
  • 04-14-2010 5:54 AM In reply to

    Re: Download email attachments

    Not working for me :/ I'm trying attachment.RemoteDownload(); MessagingApplication.Synchronize(); and then I get the email where the attachment is attached, and I RemoteDownload it, but it don't works either. email.RemoteDownload(); MessagingApplication.Synchronize(); Any hint?
  • 04-14-2010 6:01 AM In reply to

    Re: Download email attachments

    Not working for me :/ I'm trying RemoteDownload and Synchronizing in the attachment and in the email that contains it but it doesn't work either. Any hint?
  • 04-16-2010 12:09 AM In reply to

    Re: Download email attachments

    I have investigated this and foun that this doesn't always download the attachment - but it depends on the device type and account. A workaround is to set an additional status property on the message:-

    message.Properties[MessageProperty.MessageStatus] = (int)message.Properties[MessageProperty.MessageStatus] | 0x00200000;

    Depending on the account type you will probably need to call Synchronize after setting this (unless it is an ActiveSync account and you have a network connection). 

    You do not need to call RemoteDownload() on the message unless you also want to download the message body. This means it is possible to download attachments in full but not the body text - the same way you can through the Messaging application. The workaround will be incorporated into the next release (v4.2)

    Peter

     

  • 04-16-2010 6:42 AM In reply to

    Re: Download email attachments

    Hi Peter,
    I tried with:
              EmailMessage msg = email.getOriginalMail();
              // http://inthehand.com/forums/p/3380/10201.aspx#10201
              msg.Properties[MessageProperty.MessageStatus] = 
                           (int)msg.Properties[MessageProperty.MessageStatus] | 0x00200000;
              attachment.RemoteDownload();
              MessagingApplication.Synchronize();
    
    but no luck. I was trying with an emulator, ActiveSync and IMAP (Gmail) accounts and with the emulator connected via ActiveSync (so it has network connection available).
    I'll try again with a real device this weekend and get back to you.
  • 04-18-2010 5:05 AM In reply to

    Re: Download email attachments

    I believe the order is sensitive - you must mark the attachment for download first then set the property to indicate that the message has pending attachments. e.g.

    EmailMessage msg = email.getOriginalMail();

    attachment.RemoteDownload();
    // http://inthehand.com/forums/p/3380/10201.aspx#10201
    msg.Properties[MessageProperty.MessageStatus] = (int)msg.Properties[MessageProperty.MessageStatus] | 0x00200000;
    MessagingApplication.Synchronize();

  • 04-18-2010 11:49 AM In reply to

    Re: Download email attachments

    Hi Peter,
    Same results in the emulator.
    I'll try with a real device.
  • 04-21-2010 5:35 AM In reply to

    Re: Download email attachments

    Seems to be working with an "acer e101". I need to try with other devices.
    Do you know the cause of this, and how the phone model can affect? I'd like to infer where this will or won't work and looking for a workaround in those cases.
  • 04-21-2010 6:16 AM In reply to

    Re: Download email attachments

    Can you let me know the specifics of the phone models / emulators you have used? E.g. Windows Mobile version, standard or Professional Edition. Would be good to get the full version number from the Settings > System > About screen to discover the specific builds.

    Peter

  • 04-21-2010 6:30 AM In reply to

    Re: Download email attachments

    Yeah, of course.
    Emulator: Doesn't work.
    Windows Mobile 6 Profesional
    CE S5.2.1235 Build 17740.0.2.0
    .NET CF 3.5 EN
    


    Acer e101: Works fine.
    Windows Mobile 6.5 Profesional
    CE S5.2.21840 Build 21840.5.0.60
    .NET CF 3.5 ES
    

    If I am able of testing with another emulator or device I would try with emulator with 6.5 or device with 6.0. I'm not sure that I will be able of trying the later. I'll let you know.
    Thanks for your support :-)
  • 05-06-2010 2:28 AM In reply to

    Re: Download email attachments

    I don't have a 6.0 device to test on. I have tested on 6.1 and the downloading of attachments by themselves was a bit hit and miss. However it works fine if you download the enclosing email also. I marked each of the attachments for download first, then the message e.g.

    foreach (Attachment a in em.Attachments)

    {

      a.RemoteDownload();

    }

    em.RemoteDownload();

    With just the attachment RemoteDownload the message displays the green downward arrow indicating a download in progress but it doesn't actually retrieve the email. In hindsight the Attachment method should really be named MarkForDownload or similar as it only appears to function across all devices if RemoteDownload is also called on the message. It appears to work slightly differently in 6.5 as I was able to get it to download attachments individually. I'll update the documentation to make this clearer.

    Peter

Page 1 of 1 (15 items)
Copyright © 2001-2012 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting