EC-Nordbund / denomailer

A SMTP-Client implementation for deno (to send mails!)
https://deno.land/x/denomailer
MIT License
50 stars 16 forks source link

Special chars in From and Subject #36

Closed caramboleyo closed 2 years ago

caramboleyo commented 2 years ago

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.

mathe42 commented 2 years ago

Could you provide a minimal code example?

caramboleyo commented 2 years ago

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 commented 2 years ago

You can try

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

const newSubject = quotedPrintableEncode(oldSubject)

might work.

caramboleyo commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

mathe42 commented 2 years ago

Released in version 1.3.0 thanks a lot for the help!

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

nestarz commented 11 months ago

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

Is it linked ?