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.
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!