OutstandingOrderLines() lCustomer.RESET; lCustomer.SETRANGE("Send Outstanding Orders", TRUE); IF lCustomer.FINDSET THEN REPEAT SendOutstanding2Customer(lCustomer, 50074); UNTIL lCustomer.NEXT=0;
SendOutstanding2Customer(VAR pCustomer : Record Customer;ReportID : Integer) IF NOT ISSERVICETIER THEN EXIT; CLEAR(ToMail); CLEAR(FromMail); CLEAR(EmailHeader); CLEAR(EmailBody); CLEAR(EmailFoot); CLEAR(Mail); CLEAR(ServerDestination); CLEAR(ClientDestination); CLEAR(Customer); PurchSetup.GET; EmailHeader := PurchSetup."eMail Header for Sales Info"; EmailFoot := PurchSetup."eMail Foot for Sales Info"; EmailBody := ''; ToMail := pCustomer."E-Mail"; FromMail := 'info@xxxxxx.com'; ServerDestination := 'C:\Users\Public\Documents\'; Tofile := STRSUBSTNO('Outstanding orders %1,%2.pdf', FORMAT(TODAY,0,'<Year,2><Day,2><Month,2>'), pCustomer.Name); REPORT.SAVEASPDF(ReportID,ServerDestination + Tofile,pCustomer); //REPORT.SAVEASEXCEL(ReportID,ServerDestination + Tofile); ClientDestination := 'C:\Users\Public\Documents\'; FileManagement.DownloadToFile(ServerDestination + Tofile,ClientDestination + Tofile); Mail.CreateNewMessage2(FromMail,ToMail,'',Tofile,EmailHeader,EmailBody,EmailFoot,ClientDestination + Tofile,FALSE);
Answers
Codeunit 397 uses oultlok integration, which runs in user sessions, uses user mail profile, etc. When you run it from Task Scheduler there is no user session.
Try to used Codeunit 400 SMTP mail instead.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
edit: I've commented the part of sending the e-mail, just for creating the PDF file, and the rror persists, so it looks that the first error is that one.
I've changed the code:
And now, the error is:
This could be becasue of what you'ce said, about he codeUnit 397?
Thank you very much
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Thank you Slawek. And if I use Job Queues instead of task Scheduler, will it work with CU397? Or I will have the same problem?
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Thanks Slawek.
So, I think that could be a problem, because I will probably want to send e-mails from different mail accounts, depending on the customer. That will be quite easy with CU397, but if I use CU400, I should configure the SMTP server, and that is for the whole company.... Am I right?
Thank you very much
the from mail could be anyone authorised by the mail support by the mail you've config.
I've done it, I've only one config account by I've send by other depends if the department is sales, or purchase, manufacturing, etc.