go-gomail / gomail

The best way to send emails in Go.
MIT License
4.33k stars 573 forks source link

Need to encode headers when special disallowed characters are present #23

Closed jfroy closed 9 years ago

jfroy commented 9 years ago

For example, if the character "," is present in a header field, it must be encoded because it is the address separator character in the address-list (RFC 2822) production rule.

alexcesaro commented 9 years ago

This is on purpose. Can you show your code or describe what your trying to do? On Mar 9, 2015 5:22 AM, "Jean-Francois Roy" notifications@github.com wrote:

For example, if the character "," is present in a header field, it must be encoded because it is the address separator character in the address-list (RFC 2822) production rule.

— Reply to this email directly or view it on GitHub.

OVYA commented 9 years ago

Hello, I think I have encountered this problem with the character sequence \ in the To part. Here is an ECM

package main

import (
    "crypto/tls"

    "gopkg.in/gomail.v1"
)

func main() {
    msg := gomail.NewMessage()
    msg.SetHeader("From", "pi@test.fr")
    msg.SetHeader("To", msg.FormatAddress("pi@localhost", "X\\XXXXX"))
    msg.SetHeader("Subject", "Test")
    msg.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")

    mailer := gomail.NewMailer("127.0.0.1", "no-reply@test.com", "", 25,
        gomail.SetTLSConfig(&tls.Config{InsecureSkipVerify: true}))

    if err := mailer.Send(msg); err != nil {
        panic(err)
    }
}

This fails with message panic: mail: no angle-addr. Same error replacing \ by a comma.

jfroy commented 9 years ago

Yeah I ran into this trying to send an email to someone with a ',' in their name.

alexcesaro commented 9 years ago

Thanks guys! I just fixed that bug by quoting names in address headers.