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

I have the same question (0)
  • Nitin Verma Profile Picture
    21,708 Moderator on at

    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.

  • Morten Steengaard Profile Picture
    555 on at

    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;

  • Suggested answer
    Marco Mels Profile Picture
    on at

    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.

  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    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
    Morten Steengaard Profile Picture
    555 on at

    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,708 Moderator on at

    Hi,

    Good to know, that its working now.

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,606

#2
YUN ZHU Profile Picture

YUN ZHU 931 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans