Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special chars in From and Subject #36

Closed
caramboleyo opened this issue Aug 29, 2022 · 10 comments · Fixed by #37
Closed

Special chars in From and Subject #36

caramboleyo opened this issue Aug 29, 2022 · 10 comments · Fixed by #37
Assignees
Labels
bug Something isn't working

Comments

@caramboleyo
Copy link

When you use special chars in subject or from in some email clients they are not displayed properly.

I checked an email send with rainloop, where it works, and they seem to escape words containing special chars like this:
"=?utf-8?B?w5ZHS1YgS8Okcm50ZW4=?="

Meanwhile is there an escape function to archive this right now? When i copied that string into my send function it was displayed correctly.

@caramboleyo caramboleyo added bug Something isn't working triage labels Aug 29, 2022
@mathe42
Copy link
Member

mathe42 commented Aug 29, 2022

Could you provide a minimal code example?

@caramboleyo
Copy link
Author

caramboleyo commented Aug 29, 2022

Some mail clients now show ??? instead of Ö Ä Ü ß ö ä ü

import { SMTPClient } from "https://deno.land/x/denomailer/mod.ts";

const client = new SMTPClient({
    connection: {
        hostname: 'smtp.mailbox.org',
        port: 465,
        tls: true,
        auth: {
            username: 'xxx',
            password: 'xxx',
        },
    },
});
console.log('>>>send' , await client.send({
    from: 'Önsen Stärebrü <oensen.staerebrue@example.com>',
    to: 'Inga Wäregwö <inga.waeregwoe@example.com>',
    subject: 'Köttbullar recipe by Önsen Stärebrü',
    html: '<html><head></head><body>This <b>is</b> a test.</body></html>',
}));
client.close();

It does not affect the html since there any multipart gets a content-type with utf header.

@mathe42
Copy link
Member

mathe42 commented Aug 29, 2022

You can try

import { quotedPrintableEncode } from "https://deno.land/x/denomailer/config/mail/encoding.ts";

const newSubject = quotedPrintableEncode(oldSubject)

might work.

@caramboleyo
Copy link
Author

No, that looks like this:
K=c3=b6ttbullar recipe by =c3=96nsen St=c3=a4rebr=c3=bc

They seem to wrap it inside =?utf-8?B? .. ?= and hash it somehow.

@mathe42
Copy link
Member

mathe42 commented Aug 30, 2022

It looks like you can do

const newSubject = `=?utf-8?Q?${quotedPrintableEncode(oldSubject)}?=`

see https://www.telemessage.com/developer/faq/how-do-i-encode-non-ascii-characters-in-an-email-subject-line/

I can't reproduce the error with 3 different SMTP-Servers so not sure what to expect...

@mathe42
Copy link
Member

mathe42 commented Aug 30, 2022

I created a PR that implements the above fix. (#37)

You can try it by importing denomailer from https://raw.githubusercontent.com/EC-Nordbund/denomailer/feat/encode-mail-name%2Bsubject/mod.ts

@caramboleyo
Copy link
Author

caramboleyo commented Sep 2, 2022

Yes, with the new mod.ts file it works out of the box. 👏👏👏

Problem is not on the sending side, it is with the email client you open the mail. Some dont seem to assume the mail head is utf8.

@mathe42
Copy link
Member

mathe42 commented Sep 4, 2022

It semes to work (before this fix) with non spec-compliant-clients so this is an important change!

@mathe42
Copy link
Member

mathe42 commented Sep 4, 2022

Released in version 1.3.0 thanks a lot for the help!

https://deno.land/x/denomailer@1.3.0/mod.ts

@nestarz
Copy link

nestarz commented Oct 14, 2023

Hi @mathe42 , When I have ascii chars in my subject it shows weird tags in my email
image

Is it linked ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants