Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Answered

Danish letters in subject in e-mails from Lessor Payroll

Posted on by 543

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

  • Morten Steengaard Profile Picture
    Morten Steengaard 543 on at
    RE: Danish letters in subject in e-mails from Lessor Payroll

    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

  • Verified answer
    Marco Mels Profile Picture
    Marco Mels on at
    RE: Danish letters in subject in e-mails from Lessor Payroll

    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
    Morten Steengaard 543 on at
    RE: Danish letters in subject in e-mails from Lessor Payroll

    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.

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 Moderator on at
    RE: Danish letters in subject in e-mails from Lessor Payroll

    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?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans