Announcements
Hi experts,
I use Business Central version 13 on-prem.
When I make a new codeunit and use codeunit "SMTP Mail" to send an e-mail, everything works fine.
But when I use Lessor Payroll codeunit 6000802 to create an e-mail with the payslip using codeunit "SMTP Mail", then the "Subject" of the e-mail is changed from "Lønseddel" to "Lønseddel". It looks fine when I debug the program. It is only wrong on the e-mail.
Is it some error in permissions in the codeunit from Lessor Payroll (lessor.dk) or something on our server?
Best regards,
Morten
Hi Marco,
Thank you very much for your reply.
I can only reproduce the error using the Lessor Payroll module, but now I have asked my colleagues to look into Exchange, as you suggested.
Best regards,
Morten
Hello,
We had a few cases about this topic in Dynamics NAV release, but they were resolved via hot fixing. If the scenario can be reproduced in a supported release of Business Central in a CRONUS company, feel free to raise it to Microsoft. Are you using Office 365 / Exchange Online as the mail server. You can easily view how it looks like within Exchange via Exchange Message trace. Could be that there is a SMTP connector that is not correctly configured.
Thank you.
Hi Inge,
In both cases the string is just of type Text. I cannot see anything about character set anywhere.
In my codeunit that works fine, I just do this:
SMTPSetup.GET;
SMTP.CreateMessage('From me', 'from@gmail.com', 'to@gmail.com', 'Løn: Test mail', 'My body text', FALSE);
SMTP.AppendBody('Hej<br><br>');
SMTP.AppendBody('<b>Her er en lønmail</b><br>');
SMTP.TrySend;
In the codeunit from Lessor Payroll, they do this:
SMTPMail.CreateMessage(txtSenderName, txtSenderAdr, txtEmplMailAdr, txtMailSubject, txtMailText + txtMailSignature, FALSE);
SMTPMail.AddAttachment(txtSecondFileName, txtShowFileName);
IF SMTPMail.TrySend THEN BEGIN...
My codeunit works fine all the time. It does not matter if I send TRUE og FALSE as the last parameter to CreateMessage(). And it does not matter if I use the Send method or the TrySend method.
When I debug the code from Lessor Payroll, the variable "txtMailSubject" is always correct with a value from the database like "Lønseddel for perioden 01-08-22..31-08-22".
The codeunit 400 looks like this:
[External] CreateMessage(SenderName : Text;SenderAddress : Text;Recipients : Text;Subject : Text;Body : Text;HtmlFormatted : Boolean)
OnBeforeCreateMessage(SenderName,SenderAddress,Recipients,Subject,Body,HtmlFormatted);
IF Recipients <> '' THEN
CheckValidEmailAddresses(Recipients);
CheckValidEmailAddresses(SenderAddress);
SMTPMailSetup.GetSetup;
SMTPMailSetup.TESTFIELD("SMTP Server");
IF NOT ISNULL(Mail) THEN BEGIN
Mail.Dispose;
CLEAR(Mail);
END;
SendResult := '';
Mail := Mail.SmtpMessage;
Mail.FromName := SenderName;
Mail.FromAddress := SenderAddress;
Mail."To" := Recipients;
Mail.Subject := Subject; <-- at this point the variable "Subject" is correct.
Mail.Body := Body; <-- it is not possible to check if Mail.Subject is correct.
Mail.HtmlFormatted := HtmlFormatted;
IF HtmlFormatted THEN
Mail.ConvertBase64ImagesToContentId;
[External] TrySend() : Boolean
OnBeforeTrySend;
SendResult := '';
Password := SMTPMailSetup.GetPassword;
WITH SMTPMailSetup DO
SendResult :=
Mail.Send(
"SMTP Server",
"SMTP Server Port",
Authentication <> Authentication::Anonymous,
"User ID",
Password,
"Secure Connection");
Mail.Dispose;
CLEAR(Mail);
EXIT(SendResult = '');
I run my codeunit directly from the Object Designer, using the "Run" button. I run the Lessor Payroll code from inside Business Central. It is the same user.
You need to format your string correctly with the correct character set.
There are different way to do that depending on how you build the string you use.
What data type do you use for the mail subject?
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156