go-gomail / gomail

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

response returned by smtp server. #37

Closed ishail closed 8 years ago

ishail commented 8 years ago

Is there a way to receive a messageId/responseCode returned by SMTP server? Like amazon-ses returns SMTP responses as here : http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-response-codes.html

alexcesaro commented 8 years ago

I haven't check but it may be in the error message. I will have a look to make it easily accessible.

alexcesaro commented 8 years ago

Getting the reply code is quite easy. When the error is an SMTP error, a *textproto.Error is returned.

So here is how you can get the error code:

if err := d.DialAndSend(m); err != nil {
    if te, ok := err.(*textproto.Error); ok {
        fmt.Println(te.Code)
    }
}