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:
lCustomer.SETRANGE("Send Outstanding Orders", TRUE);
IF lCustomer.FINDSET THEN
And this method, calls to this one:
SendOutstanding2Customer(VAR pCustomer : Record Customer;ReportID : Integer)
IF NOT ISSERVICETIER THEN
EmailHeader := PurchSetup."eMail Header for Sales Info";
EmailFoot := PurchSetup."eMail Foot for Sales Info";
EmailBody := '';
ToMail := pCustomer."E-Mail";
FromMail := 'firstname.lastname@example.org';
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: 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
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.
aitorNAV said: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?
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 Erik P. Ernst
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
aitorNAV said: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?
That's how I can configure my O365 account. As long I own both the xxxxx.com and yyyyy.com domains, then I can associated them with my account and use either xxxxx.com or yyyyy.com email addresses as the sender when using the same O365 subscription. Technically I have associated my servers IP address with the subscription, allowing me to connect to the O365 SMTP service for my subscription.
But that's 0365, what is possible depends on which email service your customer is using.
1) So start by making sure SMTP mail works! Especially with the customer. You need to make sure that they have access to an SMTP server for their domains. You should talk to their IT department if they have one. Most do, but many have no idea about this option. All this work is wasted, if SMTP is not an option. This really has NOTHING to do with NAV at this state. This is a technical/infrastructure issue but that is your first priority.
2) Forget about enabling multiple SMTP Setups per NAV. It will require you to change the functionality almost everywhere, where the SMTP Setup is used in standard NAV. Especially with your limited knowledge about NAV. And why would you even need it, if you can do it without?
Thnak you Erik. Our customers hasn't got O365, so this is discarded. I started doieng the test with gamil, because i still haven't got the SMTP configuration of our customer, and now it is in a fair, so I must wait a few weeks more.
Do you really think that I should change too much things, weith the approach that Palle Arentoft as proposed? I don't think that iot would give me too much problem...
Even GMail allows you to associate different domains, if you use their professional offerings. Most professional email services, includes this kind of configurations If they run their own SMTP server, then certainly it will be possible.
So yes I think you should not worry to much about it, but assume that it's a matter of configuration.
Change SMTP Setup will give you more things to worry about, and you need less.
This is really interesting, thanks Erik. So i understand that, in a gmail account, I can associate both customer`s emails, and in SMTP setup, just configure the gmail account?
Sounds really good to, and as I've said before, I must wait a few weeks for the SMTP configuration, I think I will alsoread about associating the email account to one gmail account.
YOU cannot associated your customers emails/domains with your account! But if they are using GMail has their company email service, then THEY can configure it to sent from the domains they have associated with their account.
Ok... This is not happening possibly, at least with one of the accounts, that is an account from a Chinese company, that our customers is dealer from...
Hopefuly I'll have news soon about the SMTP configuration of the emails accounts, to see what I need to do...
First of all, thank you to everyone you hav ehelped me with your hints. I've solved the issue with an auxiliar table for the SMTP, and creating this method:
[External] TrySendOPT(customer : Record Customer) : Boolean
SendResult := '';
IF customer."Customer Type" < 3 THEN BEGIN
END ELSE BEGIN
Password := SMTPMailSetup.GetPassword;
WITH SMTPMailSetup DO
"SMTP Server Port",
Authentication <> Authentication::Anonymous,
EXIT(SendResult = '');
One last question... What should I do to see the sent email in the mailbox?
Thank you again!
Good work (even though I DONT LIKE that you have hardcoded the GET('X') part..
The big difference between the ordinary mail codeunit and the SMTP codeunit is two things. The normal mail requires Outlook to be installed AND you can see the sent mail in your sent folder.
SMTP does not require outlook to be installed - AND it does NOT save af copy of your mails in the sent folder. If you search a little here on Dynamics User Group you'll see that I have suggested in order to keep af copy of a sent mail that you mail yourself as BCC
Thanks Palle, really appreciatted! How would you change that "hardcode" part? It's the easiest way I think...
I would create two fields in the Sales & Receivables Setup table.
Ok, good idea. Thank you very much again!