go-gomail / gomail

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

FormatAddress shouldn't insert empty quoted name #54

Closed mackstann closed 8 years ago

mackstann commented 8 years ago

When calling FormatAddress with an empty name, like:

FormatAddress("foo@bar.com", "")

It returns:

"" <foo@bar.com>

But it would be better to return:

<foo@bar.com>

Normally it wouldn't matter all that much, but there is a bug in Go 1.5 and up that rejects such addresses with an error: https://github.com/golang/go/issues/14866

Removing the redundant "" would greatly help work around this Go bug.

In the meantime, a hack like this will work around it:

if name == "" {
    message.SetHeader("To", address) // bypass FormatAddress altogether
} else {
    message.SetAddressHeader("To", address, name)
}
alexcesaro commented 8 years ago

Fixed, thanks!

mackstann commented 8 years ago

Your fast action was very helpful to our team! Thank you!

alexcesaro commented 8 years ago

Glad it helped :smile: