auto generated mail

hi…

I need to send a autogenerated mail when my Inventory falls below Reorder point.Is it possible to send a autogenerated mail in Nav 4.0.If so ,how should i do.

I’m looking a NAV 5, right now can’t see a NAV 4 but take a look to Codeunit 400 SMTP Mail

Hi

Business Notification can be used.

AShish

can u tell me wat is business notification and how to use it

There is no code unit called SMTP MAil in Nav 4.0.There is only Codeunit 397 Mail.But it is just opening outlook.I think it is not useful to send a autogenerated mail

I see many useful functions on this codeunit 397 too, NewMessage, Send, ValidateMail… anyway take a look at this link of relationed threads in this site:

http://dynamicsuser.net/search/SearchResults.aspx?q=send+email

Bavani, Although I am a beginner at NAV, I have employed this simple solution using CodeUnit 397 and it suits our purposes without resorting to Business Notification (which can be a bear, I’ve heard) or any other more complicated solution. I have made some minor modifications to the User Setup table, adding an Email field, and have created a new table (“event Subscription”) in which the “NewCustomer” function resides. This particular event function is called from triggers in the Customer table when a new customer card is created. It looks to see who I have identifed as a subscriber, looks for that related USERID’s email address in the User Setup table, determines if that recipient is specififed as a CC or To recipient, etc., etc.

The last parameter in the NewMessage function from CodeUnit 397 is FALSE in my example. That will automatically send the email from the account of the user whose actions caused the event to be triggered. It will not require the user’s interaction. If Outlook, for example, is already opened, the user would not have to do anything for the email to be sent.

While a more experienced developer will likely point out the weaknesses and drawbacks of this approach, as I said, it is quite simple and suits our purposes.


NewCustomer(CustNo : Code[20];EventNo : Integer;EventDate : Date;EventTime : Time)

counter := 0;
CR := 13;
LF := 10;

Subject := 'A new Customer Card has been created. Customer No. ’ + CustNo

  • ’ in the ’ + COMPANYNAME + ’ company’;

Body := ‘A new Customer Card has been created. Customer No. ’ + CustNo + ’ in the ’ + COMPANYNAME + ’ company’;
Body := Body + FORMAT(CR,0,’’) + FORMAT(LF,0,’’);
Body := Body + 'It was created by user ’ + USERID + ’ on ’ + FORMAT(EventDate) + ’ at ’ + FORMAT(EventTime);

SETRANGE(“Event No.”,0);
SETRANGE(ToRecipient,TRUE);
SETRANGE(Subscribed,TRUE);
IF FINDFIRST THEN
REPEAT
IF UserSetup.GET(Subscriber) THEN
Email := UserSetup.Email;
IF Email <> ‘’ THEN BEGIN
IF counter = 0 THEN BEGIN
ToRecipient := Email;
counter += 1;
END
ELSE
ToRecipient := ToRecipient + ‘;’ + Email;
counter += 1;
END;
UNTIL
NEXT = 0;

RESET;
UserSetup.RESET;
counter := 0;
SETRANGE(“Event No.”,0);
SETRANGE(CCRecipient,TRUE);
SETRANGE(Subscribed,TRUE);
IF FINDFIRST THEN
REPEAT
IF UserSetup.GET(Subscriber) THEN
Email := UserSetup.Email;
IF Email <> ‘’ THEN BEGIN
IF counter = 0 THEN BEGIN
CCRecipient := Email;
counter += 1;
END
ELSE
CCRecipient := CCRecipient + ‘;’ + Email;
counter += 1;
END;
UNTIL
NEXT = 0;

MailCode.NewMessage(ToRecipient,CCRecipient,Subject,Body,’’,FALSE);

if i want to add a attachment using same function New Message.How should i do it

No the SMTP Mail codeunit is in NAV 5.0 - but you can just copy it from this version to NAV 4.0 and use it with no problems. As long as the customer has his maintenance and have the rights to upgrade to NAV 5.0, then there is also no license issue.

The 5th parameter in the Newmessage function is what you need to use. If there is no attachment, you do as I did in my example (i.e. use a ‘’ to indicate no file). If you need to attach a file, you put the file name in this 5th spot. The way I accomplish this in other parts of the program is to set up various reports to automatically print to a PDF Creator/Printer (Using the Printer Selections in NAV, Admin menu > Applic. Setup > General folder). By setting up the PDF printer to print to a certain file path and name, and then, in code, testing to see if the file exists, and then renaming it to a more meaningful file name, you can then include that file name as the 5th parameter of that NewMessage function and it will be automatically attached and sent with the email. If you need an exact example, I would be happy to provide it to you. It works great for my company.

thank u… give me some examples

There are many posts related to PDF Printer programs and many stories of people having success with one or the other.

For my purposes, we chose PDF Creator (http://sourceforge.net/projects/pdfcreator/) as it is FREE and it works great. We installed it as a shared network printer. We also employ PDF995 which is good, but not well-suited for the functions that I am using. So, here I go…

  1. If the attachment you are using will be in the form of a Navision report, create the report first.

  2. Download an install PDF Creator as necessary.

  3. Read the help contents for an easy summary of how to use it and how to edit the parameters via the registry. It is easy, trust me.

  4. Establish a default output file path and name so as to allow PDF Creator to create a file automatically when printing to it.

  5. In the Printer selections form in Navision, associate the Navision report with the PDF Creator printer.

  6. In the trigger for the event (yours would be in the OnValidate of the “Reorder Quantity” field), call the function that generates the report. The condition that would control if the function is called would be like “IF Inventory < “Reorder Quantity” THEN call the function…”

  7. The function would contain, among other things, the call to the system REPORT.RUN function. For example, one my calls to this function looks like REPORT.RUN(50100,FALSE,FALSE,Rec); You can find help on how to use that function in Navision help contents. Pretty straightforward stuff.

  8. This call automatically sends the report to the printer you defined in the printer selections form, which would be PDF Creator in my case. I included just the critical portion of the code that handles the file creation, deletion, renaming, etc. In my setup, we have defined that PDF Creator always print to the filepath and name T:\qanavpdf\pdf_file.pdf. So, the code looks first to see if there is a file by that name. If it exists, it will be deleted to avoid attaching any wrong version. Then the report runs, which will create that file again with the new version of your data/report. Then I give the system about 15 seconds to create the file. If, for some reason, the file cannot get created, my call to CodeUnit’s NewMessage function will not include a reference to an attached filename. If the file does get created, my code renames it using a unique filename based on a formatted timestamp. Earlier in the code, you will have established your text variables referring to the recipients, subject, and body of the email. Those texts make up the first 4 parameters of the NewMessage function. Then you include the filename text variable and the TRUE or FALSE as the last parameter. By using FALSE, the message gets sent automatically and along with it will be the attachment, your .PDF version of the Navision report that was created by the REPORT.RUN function.

//…more code preceding this next section
IF FILE.EXISTS(‘T:\qanavpdf\pdf_file.pdf’) THEN
FILE.ERASE(‘T:\qanavpdf\pdf_file.pdf’);
REPORT.RUN(50100,FALSE,FALSE,Rec);
REPEAT
IF NOT FILE.EXISTS(‘T:\qanavpdf\pdf_file.pdf’)
THEN BEGIN
SLEEP(1000);
counter += 1;
IF counter > 15 THEN BEGIN
MESSAGE(Text06);
UseAttachment := FALSE;
END;
END;
UNTIL
((FILE.EXISTS(‘T:\qanavpdf\pdf_file.pdf’) = TRUE) OR (counter = 16));
txtRandomNumber := FORMAT(TIME,0,’<Minutes,2>.<Seconds,2>’);
NewOutputFileName := ‘T:\qanavpdf\MDR Hold Tag_MDR#’ + FORMAT(MDREntryNum) + ‘_’ + txtRandomNumber + ‘.pdf’;

IF counter = 16 THEN
UseAttachment := FALSE
ELSE
IF NOT(FILE.RENAME(‘T:\qanavpdf\pdf_file.pdf’,NewOutputFileName)) THEN
MESSAGE(‘File could not get renamed. Please check to see that correct file is attached.’);

IF UseAttachment = FALSE THEN
CodeMail.NewMessage(MDRtoList,MDRccList,txtSubject,txtBody,’’,TRUE)
ELSE
BEGIN
CodeMail.NewMessage(MDRtoList,MDRccList,txtSubject,txtBody,NewOutputFileName,TRUE);
FILE.ERASE(NewOutputFileName);
END;