smtp: "wrong host name" error

1,823 views
Skip to first unread message

JONNALAGADDA Srinivas

unread,
Dec 8, 2010, 7:09:39 PM12/8/10
to golan...@googlegroups.com
Team,

        When trying to send an e-mail using `smtp.SendMail()' through GMail, I am getting the error "wrong host name".  Looking at the sources, I see that the check fails when the server identifies itself with a name different from that given to `smtp.PlainAuth()'.  In the case of GMail (as could be the case with several other providers too), the CNAME entries probably result in the server identifying itself with one of the aliases.
        Have others encountered this error, or am I doing something incorrectly?  Here is a small program that results in this error.  Thanks.

                                                                              Greetings,
                                                                                      JS

* * * *
/mnt/hgfs/mac/tmp/go$ cat g.go
package main

import (
"bytes"
"log"
"smtp"
)

func main() {
a := smtp.PlainAuth("", "a...@gmail.com", "password", "smtp.gmail.com:587")
msg := bytes.NewBufferString("Test - 1")
err := smtp.SendMail("smtp.gmail.com:587", a, "JS", []string{"b...@gmail.com"}, msg.Bytes())
if err != nil {
log.Println("!! Send failure :", err)
}
}

Evan Shaw

unread,
Dec 8, 2010, 7:32:09 PM12/8/10
to golan...@googlegroups.com
On Thu, Dec 9, 2010 at 1:09 PM, JONNALAGADDA Srinivas
<sigm...@gmail.com> wrote:
> Have others encountered this error, or am I doing something incorrectly?

Leave out the port number (and colon) when passing the host name into
the auth mechanism. That should fix it.

- Evan

JONNALAGADDA Srinivas

unread,
Dec 8, 2010, 8:00:22 PM12/8/10
to golan...@googlegroups.com
Yes, it works.  Thank you!
Reply all
Reply to author
Forward
0 new messages