Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP Content-Transfer-Encoding for html emails

Is there any reason why a Content-Transfer-Encoding of quoted-printable would be screwing up a link, when sent from a SMTP server?

Example:

After setting the mail from, rcpt to and entering data mode, send this (emails removed):

From: Me <[email protected]>
To: You <[email protected]>
Subject: Email Test
Mime-Version: 1.0;
Content-Type: text/html; charset="UTF-8";
Content-Transfer-Encoding: quoted-printable;

<html>
<body>
<a href="https://www.google.com/">Google</a>
</body>
</html>

Then the email source is somehow getting screwed up and the a tag is changed to <a href=3D"ttps://www.google.com/&quot;">Google</a> (missing h from https).

If I change the Encoding to be 7bit then everything works fine.

like image 663
grpcMe Avatar asked Sep 01 '25 04:09

grpcMe


1 Answers

For anyone that happens to come across this post - the issue was a simple one but not one that was immediately obvious to begin with.

When using quoted-printable you have to make sure you're passing properly encoded data. I was not. I was passing normal HTML through, thinking that was ok.

So in my example, the <a> tag would have to be encoded to <a href=3D"https://www.google.com/">Google</a> then it works.

I was trying to implement this using Go, so below is a function that will implement this functionality...

// Returns a properly quoted-printable string
func toQuotedPrintable(s *string) error {
    var b bytes.Buffer
    w := quotedprintable.NewWriter(&b)

    _, err := w.Write([]byte(*s))
    if err != nil {
        log.Println("Error while decoding to quoted-printable", err)
        return err
    }

    err = w.Close()
    if err != nil {
        log.Println("Error while decoding to quoted-printable", err)
        return err
    }

    *s = b.String()
    return nil
}
like image 184
grpcMe Avatar answered Sep 04 '25 02:09

grpcMe