we have one new requirement to read outlook from Navision
Details
User will send one text file. The text file will be on specific format, then program should read new mails from outlook and download the file to a pacific place . Read the text file and creates item journals and posts it.
The main point program should download the attachment file, through outlook automation we can download the attachment .
Here is one example for downloading the mail
Create the automation variables check the image
Outlook mail Codeunit
IF ISCLEAR(outlookapplication) THEN CREATE(outlookapplication,FALSE); outlooknamespace:=outlookapplication.GetNamespace('MAPI'); outlooknamespace.Logon('Outlook','',TRUE,TRUE); outlookMAPIFolder:=outlooknamespace.GetDefaultFolder(6); //6 means inbox outlookitems:=outlookMAPIFolder.Items; Findcriteria:='[ReceivedTime]>'+Text001+FORMAT(TODAY-1) +Text001+' AND [Unread] =true '; outlookitems:=outlookMAPIFolder.Items.Restrict(Findcriteria); I:=1; endofloop:=outlookitems.Count; WHILE I<=endofloop DO BEGIN outlookemail:=outlookitems.Item(I); outlookAttachments:=outlookemail.Attachments; AttCount:=outlookAttachments.Count ; IF AttCount>0 THEN FOR K:=1 TO AttCount DO BEGIN Path:='E:\Outlook Attachment path\'+outlookAttachments.Item(K).FileName; outlookAttachments.Item(K).SaveAsFile(Path); END; I+=1; END;
create one Outlook Attachment path folder and run the codeunit
now the codeuint will filter last two days unread mails from outlook and all the attachment files will save to E:\Outlook Attachment path\
you can download the object file from here
Tips
Find criteria we can use different conditions
eg: [ReceivedTime]>’18/08/13′ AND [Unread] =true AND [Subject] = ‘item’
check the link
http://msdn.microsoft.com/en-us/library/office/aa210275%28v=office.11%29.aspx
Fantastic information. Thank you so much for sharing it.
LikeLike
good post…. need more posts from u….
LikeLike
Hello
can I downlod file .txt format please Or send me email to elhamdir@laposte.net
I not sur what is type off this variable endofloop?
thanks
LikeLike
you can download fob file from this link https://www.dropbox.com/s/afwr4e1qq6vrpto/50099%20Outlook%20mail.fob
endofloop is an integer variable , thanks
LikeLike
Microsoft Dynamics NAV Development Environment
You cannot create an Automation object “outlookapplication” on Microsoft Dynamics NAV Server. You must create it on a client computer.
OK
LikeLike