Quantcast
Channel: ImapX 2
Viewing all articles
Browse latest Browse all 1952

New Post: Download attachments files from gmail

$
0
0
Hello!
I am not able to download attachments files from a gmail account.
My code:
 var client = new ImapClient("imap.gmail.com", 993, true);

            if (client.Connect())
            {

                if (client.Login("mail@gmail.com", "pass"))
                {
                    //                   

                    // login successful
                    Folder folder = client.Folders.Inbox;

                    //client.Behavior.MessageFetchMode = MessageFetchMode.Basic;

                    List<Message> listaMensajes = new List<Message>();

                    Message[] mensajes = folder.Search("UNSEEN", ImapX.Enums.MessageFetchMode.Tiny);


                    foreach (Message mensaje in mensajes)
                    {


                        if (mensaje.From.Address.Equals("mymail@gmail.com") && mensaje.Attachments[0].ContentType.MediaType.Equals("application/pdf"))
                        {
                            listaMensajes.Add(mensaje);
                            //mensaje.Seen = true;
                            mensaje.Download(ImapX.Enums.MessageFetchMode.Attachments);
                            string nombreFichero = mensaje.Attachments[0].FileName;
                            mensaje.Attachments[0].Download();
                            byte[] fichero = mensaje.Attachments[0].FileData;
                         }
                  }
          }
   }
At the time mensaje.Attachments[0].Download(); is executing, i get this exception:

_A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll

Additional information: Exception has been thrown by the target of an invocation._

Thanks!

Viewing all articles
Browse latest Browse all 1952

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>