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...
Suggested answer

Local characters in e-mail subject

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

I use Business Central version 13 on-prem.

I have made a new codeunit that uses codeunit "SMTP Mail" to send an e-mail. It works fine (also with Danish characters in the e-mail subject and body).

But if I add an attachment (a pdf-file), the Danish characters in the e-mail subject, is shown wrongly in Outlook.

The header of the e-mail has this, when it works:

Subject: Løn: Test mail

Content-Type: text/plain; charset="utf-8"

and this, when it does not work:

Subject: Løn: Test mail

Content-Type: multipart/mixed;

                      boundary="--boundary_28_3eeb0768-ce3e-47ce-810a-b3510541816c"

The subject of the e-mail with the attachment is shown as "Løn: Test mail".

Here is my codeunit:

SMTP.CreateMessage('From me', 'my-email@gmail.dk', 'my-email@gmail.dk', 'Løn: Test mail', 'The body', false);

SMTP.AddAttachment('C:\\temp\\Some-real-file.pdf','The-filename-to-show-in-the-mail.pdf');

SMTP.TrySend;

If I outcomment AddAttachment, everything works fine. If I add the attachment, the DotNet "Mail" object in codeunit "SMTP Mail" forgets that it is in Denmark.

Hope you can help.

Morten

  • Suggested answer
    Nitin Verma Profile Picture
    21,569 Moderator on at
    RE: Local characters in e-mail subject

    Hi,

    Good to know, that its working now.

  • Suggested answer
    Morten Steengaard Profile Picture
    555 on at
    RE: Local characters in e-mail subject

    Hi both,

    Thank you for your reply.

    I haven't tried your latest suggestion, Nitin.

    The problem is solved. The mail server was set up in a wrong way and everything works fine now, as we use another server.

    Best regards,

    Morten

  • Suggested answer
    Nitin Verma Profile Picture
    21,569 Moderator on at
    RE: Local characters in e-mail subject

    Hi,

    Do one thing, Create a Text constant of your Subject part and call that text constant as your emailmessage's subject parameter. In your case it would be Label instead of TextConstant.

    Name ConstValue

    EmailSubj Løn: Test mail

    SMTP.CreateMessage('From me', 'my-email@gmail.dk', 'my-email@gmail.dk', EmailSubj, 'The body', false);

    Thanks.

  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: Local characters in e-mail subject

    Hello,

    If you can provide a repro in standard CRONUS Denmark A/S company, feel free to raise it to Microsoft via partnercenter.microsoft.com .

    Thank you.

  • Morten Steengaard Profile Picture
    555 on at
    RE: Local characters in e-mail subject

    Hi Nitin,

    Thank you for your reply.

    I have tried both with "true" and "false" in the last parameter. That didn't help.

    The pdf file that I have, has been made by a module called Lessor Payroll. It is not something that I create. And I don't have a report with number 10075.

    I have tried to do this:

    SMTP.CreateMessage('From me', 'my-email@gmail.dk', 'my-email@gmail.dk', 'Løn: Test mail', 'The body', false);

    ltServerFileName := FileManagement.ServerTempFileName('PDF');

    ltServerFileName := FileManagement.GetDirectoryName(ltServerFileName) + '\MS.PDF';

    FileManagement.CopyClientFile('C:\\temp\\MS.PDF', ltServerFileName, true);

    SMTP.AddAttachment(ltServerFileName, FileManagement.GetFileName(ltServerFileName));

    SMTP.TrySend;

    I cannot copy the file, because "access to the path is denied".

    ---

    I have also tried my original solution with a new txt-file, that I have saved as UTF-8. That didn't help either:

    SMTP.CreateMessage('From me', 'my-email@gmail.dk', 'my-email@gmail.dk', 'Løn: Test mail', 'The body', false);

    SMTP.AddAttachment('C:\\temp\\Some-real-file.txt','The-filename-to-show-in-the-mail.txt');

    SMTP.TrySend;

  • Nitin Verma Profile Picture
    21,569 Moderator on at
    RE: Local characters in e-mail subject

    Hi,

    Try two things with yellow mark.

    1. SMTP.CreateMessage('From me', 'my-email@gmail.dk', 'my-email@gmail.dk', 'Løn: Test mail', 'The body', true);

    2. Save the attached in servertemp file and then load it in attachment


    FileMgt Codeunit File Management

    ltServerFileName := FileMgt.ServerTempFileName('PDF');
    ltServerFileName := FileMgt.GetDirectoryName(ltServerFileName) + '\Order.PDF';

    I am guessing here you are sending your document PDF file from Posted Data

    SalesHeader.filters

    IF REPORT.SAVEASPDF(10075,ltServerFileName,SalesHeader) THEN BEGIN
    SMTP.AddAttachment(ltServerFileName,FileMgt.GetFileName(ltServerFileName));

    SMTP.trysend;

    Not sure will it work for you.

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans