Auto interrogating a mail box

Is it possible to interrogate a mail box automatically from within NF v2.6 and then take an attachment and use this for creating orders ? If so would it be done using automation? Also, where would I start ? Thanks in anticipation

Sounds to me like a task for which I would look for a solution outside Navision. Maybe Visual Basic, maybe Delphi, maybe C++ - whatever you feel most at home with. You will probably need a programming environment which gives you more control over Windows, mail client, scheduler, attachment retrieval and parsing, etc. The result could be inserting header/lines records in “interface” tables, from where you can create the actual orders with Navision programming. John

The native Navision doesnt have any ability to read mail, only send. Writing an OCX in whatever language would be a nice addon -something I’ve thought a lot about but never had the time to do. It should really be an internet based client, rather than exchange, or both. Using an internet mail based OCX will mean it could collect mail from any number of types of mail servers - and would be compatible with exchange. For full exchange features, an OCX could be written to supplement the first, or be a totall seperate OCX. I am not sure what v3 will have in the way of this kind of feature but I dont think it will be there. Craig Bradney Project Manager - Technical Navision Solutions & Services Deloitte Growth Solutions Deloitte Touche Tohmatsu P:+61-2-9322-7796 F:+61-2-9322-7502

The answer to Deans question is definitely “yes”. It’s possible and I did it already a couple of times. The only OCX you need is MAPI32.OCX which comes with Windows. You don’t have to write an own OCX. Marcus

Fabian, I’m very interested in this. Can you tell me what you need next to the MAPI32.OCX? And where can I find documentation regarding this ocx (how to use these functions and how to embed this into Navision etc…) Thanks, Roelof.

My main thoughts for writing a new OCX would be to do some preparsing so the email could be viewed in Navision - ie text field size limits, and auto interrogation of emails that have particular subjects for subscriptions etc etc… Craig Bradney Project Manager - Technical Navision Solutions & Services Deloitte Growth Solutions Deloitte Touche Tohmatsu P:+61-2-9322-7796 F:+61-2-9322-7502

Roelof, As you might suspect there are lots of issues you might be aware of if you want to process e-mails. The most important one is (as Dean said in his initial post) that the order has to be sent as attachment, not as body-text! Attachments can have unlimited size whil Navision can only handle 250 Chars in the body-text. Let’s start with the order-form, the html-file which will be filled out by the user and be posted to you: There are generally two methods how a html form can be sent to an e-mail address: 1) mailto: 2) post: The mailto method does not work if Outlook is installed (Microsoft admitted the bug but never corrected it) making this method quite useless the post method works for all operating systems. The contents of the filled order-form is being sent to a script on your webserver (or the one of your provider) and is being processed. In the above example the script is located at Generally there are two kind of scripts: Linux / Sun Solaris: formmail.cgi or formfile.cgi (respectively .pl). Both scripts scan and process the order form and basically send you a list with values (keyvalue and contents). Example: customerno = 1234 Customername = Chronus Intl. Item1 = 50050 Qty1 = 4 etc. formmail.cgi sends the order as body-text while formfile.cgi processes an attachment. Microsoft Exchange Server: Scripts like formmail and formfile should usually be available. Typically the file extension is .asp Before you start, you should therefore check the following: * Does the provider (web-provider of your customer) have Sun, Linus or MS-Server? * Does he have a formfile script which can send the order as attachment? * How can you configure the script? (usually using hidden text within the form) — Now let’s come to the next point, how to process the attachment within Navision. Before you start, you need a developer license for MSMAPI32.OCX. This license is automatically installed if you install any Microsoft developer package such as VB, C++ or Office Developer. If you do not have a license, declare a Automation variable from MSMAPI.OCX in a codeunit and try to compile you will get an error message liek "GUID {000blabla} cannot be resolved} Within your Codeunit you need to variables of type OCX which define the reference to your e-mails: Mails : Microsoft MAPI Messages Control, version 6.0 MAPISession : Microsoft MAPI Session Control, version 6.0 Now scan through your Inbox, look for mails with attachments and process the attachments: (note: Underscored at the beginning of the lines are for better readability in this message). MAPISession.SignOn; // Get new mails MAPISession.DownLoadMail (True); IF MAPISession.SessionID = 0 THEN MAPISession.SignOn; Mails.SessionID := MAPISession.SessionID; Mails.FetchUnreadOnly(TRUE); Mails.Fetch(); keytext := ‘NavisionFLAG=CHRONUS’; // see note below prog. code // Only look for messages with Attachments FOR MeldungNr := 0 TO (Mails.MsgCount-1) DO BEGIN __Mails.MsgIndex(MeldungNr); __IF Mails.AttachmentCount > 0 THEN BEGIN ____FOR AttachmentNr := 0 TO (Mails.AttachmentCount - 1) DO BEGIN ______Mails.AttachmentIndex(AttachmentNr); { ______MESSAGE (‘Message %1 from %2 with Attachment-Path %3, Name %4, Type %5, Position %6, Subject %7’, ______MeldungNr, ______Mails.MsgOrigAddress, ______Mails.AttachmentPathName, ______Mails.AttachmentName, ______Mails.AttachmentType, ______Mails.AttachmentPosition, ______Mails.MsgSubject); } { Read the first 250 Bytes of Attachment and make sure this attachment contains a Navision order and not something else } ______f.TEXTMODE (FALSE); ______IF NOT f.OPEN (Mails.AttachmentName) THEN ________ERROR (‘File %1 not found’,Mails.AttachmentName) ______ELSE BEGIN ________NumBytesRead := 0; ________st := ‘’; ________tx1 := ’ '; ________WHILE (f.READ(ch) > 0) AND (NumBytesRead < 250) DO BEGIN __________tx1[1] := ch; __________st := st + tx1; __________NumBytesRead := NumBytesRead + 1; ________END; ________IF STRPOS (st, KeyText) > 0 THEN BEGIN __________ProcessAttachment (f); ________END; ______END; ____END; __END; END; It is clear that the order must contain all necessary fields to generate a Navision purchase order. Besides the obvious fields (like Customer number etc) it’s also possible to include hidden fields in the form. The first field in every html-form should contain a keyword such as The attachment will contain as first key=value - string the phrase “NavisionFLAG=CHRONUS” Finding this sting within the first 250 Characters of the attachment is a signal that this attachment is in fact a navision order and not a picture or word document. I hope this helps. Enjoy! Marcus

Marcus, Thanks! You did a great job to help me out. Thanks again. Roelof.