*Connect to Outlook aplicacao = createobject("outlook.application") espaco = aplicacao.GetNamespace("MAPI") * Instantiate 'Inbox' folder **** inbox = espaco.GetDefaultFolder('aabbcc')&&error ****inbox=espaco.GetMailFolder('aabbcc')&&error inbox = espaco.GetDefaultFolder(6) * Instantiate 'Deleted Items' folder eliminados = espaco.GetDefaultFolder(3) * Count messages in Inbox Contagem = inbox.Items.Count if Contagem>150 messagebox('You have '+alltrim(str(Contagem))+' Emails in your Outlook Inbox, Please Clear it To 100 - Maximum.'+chr(10)+'THE OPERATION CANCELD!',0+16) return endif inewemails=0 * Navigate messages for i = 1 to contagem * Get specific message mensagem = inbox.items(i) * Read message 'subject' field assunto = alltrim(mensagem.subject) if left(assunto,2)<>'TR' loop endif inewemails=inewemails+1 * Count attachments total_attachments = mensagem.attachments.count * Read attachments and save it to a disk folder if total_attachments > 0 * Browse through attachments for x = 1 to total_attachments nomeficheiro = mensagem.attachments(x).filename nomeficheiro2 = "C:\exps\sent\" + m.nomeficheiro mensagem.attachments(x).saveasfile(nomeficheiro2) next endif * Move the complete message to deleted items * remember that object 'eliminados' is an instance to * 'deleted items' folder mensagem.Move(eliminados) * release message objects mensagem = null assunto = null next * Close outlook aplicacao.quit * Release objects aplicacao = null espaco = null inbox = null Contagem = null eliminados = null if inewemails=0 messagebox('No Emails Arrived',0+64) else cnewemails=alltrim(str(inewemails)) messagebox(cnewemails +' Email/s Imported successfuly!',0+64) endif>* Count messages in Inbox
>*** Get a local referenece to the collection of of items in the Inbox >loItems = loInbox.Items > >*** Process all the items in the inbox >*** If it is a mail item, save it and process the attachments >IF VARTYPE( loItems ) = 'O' > FOR EACH loItem IN loItems > IF loItem.Class = 43 && olMail > *** Process the message and the attachments > ENDIF > ENDFOR >ENDIF >>
loRootFolder = oNameSpace.GetDefaultFolder( 6 ) && Inbox