web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Danish letters in subject in e-mails from Lessor Payroll

(0) ShareShare
ReportReport
Posted on by 555

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

I have the same question (0)
  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    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?

  • Morten Steengaard Profile Picture
    555 on at

    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.

  • Verified answer
    Marco Mels Profile Picture
    on at

    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.

  • Morten Steengaard Profile Picture
    555 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans