Options

E-mail through NAV5: needs clarification

ReedbergReedberg Member Posts: 68
Hello all,
I am a NAV developer. My client uses NAV5. I am working on a project to send e-mail through NAV. For sending e-mail I use codeunit 400. E-mail are send with the help of NAS.
I have several questions which are not clear for me, so any help will be appreciated!

1. I added a timer to the standard NAV codeunit E-Mail Dispatcher (5065). This timer will be run by NAS. Codeunit E-Mail Dispatcher is SingleInstance.
My client already has some integration which is run by NAS. There is a custom codeunit "WMS Integration" which contains timer "WMS Timer". "WMS Timer" calls functions which do some integrations with WMS. Custom Codeunit "WMS Integraion" is not SingleInstance. It works fine.
I am wondering why developers which worked on the project before (they already left) be decided to make "WMS Integration" codeunit not a SingleInstance one. This codeunit is called only from Codeunit 1, from NasHandler function.
May it be the case that NAS has some problems with SingleInstance objects or something like this?

2. I found that similar task was implemented for another customer of my company. I found that following code which was actually sending e-mails:
SmtpMail.CreateMessage("Sender Name", "Sender E-mail", '',Subject,Body,FALSE);
SmtpMail.Send;
COMMIT;
SLEEP(200);   
What is SLEEP function designed for? Can I remove it?
3. I tried to send with the help of 397 codeunit. This codeunit uses automation with type 'NS Outlook Synchronization Handler'. When I send e-mails through 397 codeunit they remain in the "Send" box in my Outlook client. But the task is to send messages to several recipients.
FOR FileNameCounter := 1 TO ARRAYLEN(CCNames) DO BEGIN
  IF CCNames[FileNameCounter] <> '' THEN BEGIN
    ORecipients := OSendMail.Recipients;
    ORecipient := ORecipients.Add(CCNames[FileNameCounter]);
  END;
END;
Method Add works just fine for adding recipients. However when I try to send message I got the error 2699 with now further description. The e-mail is not send, instead it is saved in templates of my Outlook client. I found several posts where people encountered the same issue, but I didn't manage to find a solution.
Does anybody know a way to send e-mail through 397 codeunit to several recipients?

Answers

  • Options
    ssinglassingla Member Posts: 2,973
    There are lot of posts on the forum related to email you could try searching them. I though don't use standard NAV method but instead rely on SQL Server database mail. IMHO it is more stable and provides email log feature. Further NAV hangs (sleeps) while the mail is send (that's why sleep command is used) but SQL executes within seconds. The only catch is that it requires SQL server for execution.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • Options
    einsTeIn.NETeinsTeIn.NET Member Posts: 1,050
    Reedberg wrote:
    May it be the case that NAS has some problems with SingleInstance objects or something like this?
    No, NAS doesn't have any issue with SI codeunits. It's quite the contrary, it needs at least one SI codeunit to run properly. In most cases it's the starting codeunit. This codeunit holds some functionality to start your needed process, either based on timer or based on some external event trigger call.
    Reedberg wrote:
    What is SLEEP function designed for? Can I remove it?
    http://msdn.microsoft.com/en-us/library/dd338921.aspx
    In my opinion SLEEP is used in two scenarios. Either you want to make sure that system control is detached from your current function (that way other processes have a chance to do their job in the meantime) or you started some kind of external process and you don't know how long it'll take, so you wait (sleep) for a certain period of time. Both have to be considered very carefully as they indicate that there's maybe something wrong with your solution design.
    "Money is likewise the greatest chance and the greatest scourge of mankind."
  • Options
    ReedbergReedberg Member Posts: 68
    Dear ssingla,
    Thank you for your reply, my client has a very strong policy regarding production database and SQL-server, even system administrator of the Production DB does not have access to SQL. In order to get such an access there must be special authorization, etc.. So, in my particular case SQL option can not be used.

    einsTeIn.NET
    Thank you for your reply!

    Regards,
    Reedberg
Sign In or Register to comment.