Hello!
I am not able to download attachments files from a gmail account.
My code:
_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!
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!