Local characters in e-mail subject

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', '[email protected]', '[email protected]', '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

Best Answer

  • SanderDkSanderDk Member Posts: 497
    Answer ✓
    It sounds like your PDF file is in some weird encoding. If I copy paste you code it works fine with danish characters
    6d35knk65brv.png

    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.

Answers

  • KTA8KTA8 Member Posts: 388
    I think than those characters aren't in utf-8, you should use another iso enconding instead. Google says than danish one is ISO 3166 o ISO 639.
  • MortenSteengaardMortenSteengaard Member Posts: 130
    The e-mail that works has a header with a charset = UTF-8, so that must be ok.

    But that is not the problem. The problem is that I cannot set the encoding anywhere. It is automatically set to UTF-8 (which works) and if I add an attachment to the e-mail, the encoding has changed to something that does not work.
  • KTA8KTA8 Member Posts: 388
    I couldn't find those characters there https://en.wikipedia.org/wiki/UTF-8

    So on, the subject it's a text, I don't get why do you related that with the attachment
  • SanderDkSanderDk Member Posts: 497
    Answer ✓
    It sounds like your PDF file is in some weird encoding. If I copy paste you code it works fine with danish characters
    6d35knk65brv.png

    For help, do not use PM, use forum instead, perhaps other people have the same question, or better answers.
  • MortenSteengaardMortenSteengaard Member Posts: 130
    Hi both,

    Thank you for your reply. The test from SanderDk helped a lot.

    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
Sign In or Register to comment.