"Client callbacks are not supported" error

Hi everyone,
First of all, I’m gonna explain my intentios of doing this development, may be I am a bit confused, and I can do it in another way that doesn’t launch this error.
My idea is to periodically send an email with an attached PDF to different customers. This is an approach to the developmet.
First of all, I run this method in a CodeUnit:

OutstandingOrderLines()

lCustomer.RESET;
lCustomer.SETRANGE("Send Outstanding Orders", TRUE);
IF lCustomer.FINDSET THEN 
  REPEAT
    SendOutstanding2Customer(lCustomer, 50074);
  UNTIL lCustomer.NEXT=0;

And this method, calls to this one:

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);

As you can see, I find some customer, and I send a report to each of them. First of all, I create the PDF file in a folder, and afterm I attach it to the email.
This works perfectly when I run the codeUnit, but as I want to send the mails periodically, I must to use the “Task Scheduler”. For this, I have created an script that calls to the method in the CodeUnit, but when I run the script, I can see this error:
pastedimage1526993845343v1.png
I’ve read in different places, that could be somethin with the “GUIALLOWED” property, but I don’t see how should I fix this issue.
Any hint?

Thank you vey much

Hi Aitor,

Why are you using FileManagement.DownloadToFile() function? If I understand correctly, you are launching this process trought web service, in that case there are no client at all, you don’t need to download file, your “client” is your server.

Try to remove “ClientDestination” part and test it again.

Hola Ponç,

Thank you for your answer. I’ve changed mycode:

//<<180503-01>>
IF NOT ISSERVICETIER THEN
  EXIT;
// IF  GUIALLOWED 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@basemetalurgica.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);
Mail.CreateNewMessage2(FromMail,ToMail,'',Tofile,EmailHeader,EmailBody,EmailFoot,ServerDestination + Tofile,FALSE);

And now the error is:

System.Web.Services.Protocols.SoapException: Microsoft Dynamics NAV Business Web Services attempted to issue a client callback to create a DotNet object: Microsoft.Office.Interop.Outlook.ApplicationClass 
(CodeUnit 397 Mail). Client callbacks are not supported on Microsoft Dynamics NAV Business Web Services.
   en System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   en System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   en SendOutsOrders.WebService.BasemetaFunc.OutstandingOrderLines() en c:\Users\Administrador\Documents\Visual Studio 2012\Projects\SendOutsOrders\SendOutsOrders\Web 
References\WebService\Reference.cs:l¡nea 341
   en SendOutsOrders.Program.Main(String[] args) en c:\Users\Administrador\Documents\Visual Studio 2012\Projects\SendOutsOrders\SendOutsOrders\Program.cs:l¡nea 26

I’ve read in another post that this could be because I am using CodeUnit397, which uses Outllok Integration, and this could make the error. Do you think that this could be becasue of that, and using CU 400 will be better?

Thnak you very much

Yes, you need to be using codeunit 400 SMTP Mail, if you want to call it without having Outlook installed. Codeunit 397 depends on a user interface and Outlook. SMTP mail needs an SMTP mail server.

Thank you Erik, as always.
And if I use Job Queues instead of task Scheduler, will it work with CU397? Or I will have the same problem? It’s important to know that, in the server, outlook is installed…

Hola Aitor,

Job Queue will have same beaviour than task schyeduler, will run on server, you can’t run anything there that will require user interaction and CU397 will.

Hola,

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

It’s actually easier to have different senders depending on the customer with SMTP (400), than with Mapi (397). MAPI will always use the account configured with Outlook, whereas SMTP allow you to specify it per mail.

In Mapi, I configure the direction with this statement:

FromMail := 'info@xxxxxx.com';

Can I do something like this with SMTP? I thought that the only sender account was the one that was configured in the SMTP server-…

Yes. If you do so in Mapi, then it doesn’t really give you anything. Check the received mail, it will be send from the MAPI user.

Only exception is that you can configure some account to be used by more users.

Thank you Ernst, I’ll work on it!

I’ve got a few more task to do, but when I try this, I’ll give the feedback!!

Really thanks!

Hello [mention:61b2aa9ce72e429baa1ef43208ddbea4:e9ed411860ed4f2ba0265705b8793d05]

Until I receive the SMTP configuration data from our customer, I’m making test configuring with my own gmail account. I’m receiveing the mail correctly, but I’'m receiving from my gmail account, instead of the company mail. I’m creating the message this way:

mailSMTP.CreateMessage('info@xxxxxxx.com','info@xxxxxxx.com','yyyyyyy@yyyyyy.coop','envio prueba',textoCuerpo, FALSE);
mailSMTP.AddAttachment(ServerDestination+Tofile,Tofile);

What should I change for configure the email that I want to send from?

Thank you very much!!

The syntax for the function is:

CreateMessage(SenderName: Text;SenderAddress: Text;Recipients: Text;Subject: Text;Body: Text;HtmlFormatted: Boolean)

So you need to change the sender address, the first is just the display name. But it also depends on the SMTP server you are using. If you use GMails SMTP, then you are actually using your own account. I’m using Office365’s SMTP servers to send mails from my NAV, and here the email I’m using just need to been from one of the domains I have registered on my subscription.

So, as I supposed, I was using correctly the CreateMessage function, but the issue is other… Isn’t possible to send emails from different accounts if we have configured a gmail account on SMTP?

Our customer, needs teh mails to be sent from different account, depending on if they are from Spain, or not.

AS far as I understood, you have configures your O365 account, and yo can’t send mails from he account of that susbscription, am I right? If the custoemr hasn’t got a O365 subscription, can we send emails from different account in another way? Or it’s just imposible? If it’s possible, which are the requisites?

Thank you very much!

Codeunit 400 only rely on the SMT-mail Setup table. So if you want to send emails from different UserIDs then you either have to

  1. Change Codeunit 400 where you have inserted the correct Userid/password/smtp-server in a temporary record

  2. Add the fields from the SMTP-Mail setup table to eg. a user-table and change codeunit 400 to use that.

Interesting… As far as i underastand on what are you saying, I suppose i should change the “TrySend” method, am I right? In that method is where I get the SMTP configuration. But as I see, the “from direction” is setup in the “CreateMessage” function…

Hi again,

I’ve been trying to do differentes test, and debugging, but I think I’m quite lost in this issue.

My code is like this:

mailSMTP.CreateMessage('info@xxxxx.com','info@xxxxx.com','xxx@yyy.coop','envio prueba',textoCuerpo, TRUE);
mailSMTP.AddAttachment(ServerDestination+Tofile,Tofile);
MailSent := mailSMTP.TrySend;

When I call to “CreateMessage”, it goes to CU400, and I can see of the “Mail” DOTNET variable, has the correct direction, the one I’me passing through parameters.

But when I came back to my CU, “mailSMTP” variable has the parameters that have been configured in the SMTP configuration. I’m trying to find the point that validates the SMTP setup, and I’m changing some values, but when I change those values, i get an authentication error…

How can I “skip” the validation or, change those values?

Any hint will be appreciated, thank you very much

That was NOT quite what I wrote! I wrote that if you send mails using GMails’ SMTP server, then you need to make sure that you’re allowed to use the sender email address. O365 works fine, but I need to link the domain I’m sending from (i.e. if I’m sending from dynamicsuser.net - then this domain needs to be registered in O365 first. I cannot send a mail with an email from a domain not associated with 0365. I’m not familiar with how GMail works, but assume its something similar.

If you use xxxxx.com as your sender domain, then that domain either has to be @gmail.com or in another way associated with the same account you used to authenticate your SMTP setup. What happens when you use the Test function in SMTP setup? Before dealing with your custom code, then you should make sure SMTP Setup has been tested.

Hi [mention:61b2aa9ce72e429baa1ef43208ddbea4:e9ed411860ed4f2ba0265705b8793d05]

Thanks for your answer. FIrst of all, I must say that that our idea is not using gmail in the customer. I’m using gmail for the test, with the hope that it will help me, but it seems to be more problematic.

Our customer has a mail account for the customwers from spain with the domain “xxxxx.com”, and another domain for the customer from the rest of europe, “yyyyy.com

Is it possible to send emails from different domains? How should setup the SMTP? With which domain?

Sorry about my question, I am auto-didact with all this, and I am really lost about his…

Thank you all again for everything

The answer is still YES, it is possible to send emails with different SMTP Accounts, but still not without programming.

This can be done with less than one hour of programming.

  1. Make a copy of the SMTP Table and change the field PRIMARY KEY to eg. COUNTRY

  2. Create a page to the new SMTP-Table

  3. Add the page to a Role Center

  4. Add records with countryspecific SMTP mail settings

  5. Add the new SMTP Table primary key field to eg. Customer Posting Group (If that groups yours customers

  6. Change the mail send codeunit where it tests from where the customer comes from simply by doing a Transferfields in code.

But before you do ANYTHING make sure that it works with at least one SMTP-mail setup