Faça o download do anexo do Exchange usando o Exchange Web Services
Estou tentando usar o código a seguir para conectar e baixar um anexo de email em uma caixa de entrada usando C # e Serviços Web do Exchange, mas estou recebendo um erro 'System.ArgumentOutOfRangeException' e não consigo entender por que. Pesquisei no Google por uma resposta, mas não consigo encontrar uma ou as respostas que encontro são para versões muito antigas do EWS.
Sei que o restante do código geralmente funciona, pois posso acessar outras informações relacionadas ao email, mas não acessar o anex
Alguém pode me mostrar o erro dos meus caminho
Desde já, obrigado
Jame
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential("MYLOGIN", "MYPASSWORD", "MYDOMAIN");
service.Url = new Uri("https://MYMAILSERVER/EWS/Exchange.asmx");
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1000));
foreach (Item item in findResults.Items)
{
if (item.HasAttachments && item.Attachments[0] is FileAttachment)
{
FileAttachment fileAttachment = item.Attachments[0] as FileAttachment;
fileAttachment.Load("C:\\temp\\" + fileAttachment.Name);
}
}
}
}
Resolvido mas novo problema
Eu resolvi o problema agora, alterando o 'foreach (item do item em findResults.Items)' para 'foreach (item EmailMessage em findResults.Items)', mas agora preciso descobrir como enumerar os anexos - qualquer idéia que alguém tenha ?