badoux / checkmail

Golang package for email validation
MIT License
710 stars 92 forks source link

Doesn't work with Yahoo! Any other ideas? #2

Closed masnun closed 7 years ago

masnun commented 7 years ago

I know Yahoo! always sends 250 even if the mailbox does not exist. Are there any work arounds or ideas I could use? I have seen some commercial services verify Yahoo! email addresses properly. I was wondering how they do that.

BTW, thank for your awesome work!

badoux commented 7 years ago

Yes Yahoo! always sends 250 after the "RCPT TO" command. I just noticed that they respond with _"554 delivery error: dd This user doesn't have a yahoo.com account (3378887xxxx33829@yahoo.com) [0] - mta1203.mail.ne1.yahoo.com" after the DATA command.

I will update the pkg with the improvement.

Thanks for you remark

badoux commented 7 years ago

Hmmm... Even with wrong headers the mail is sent after the "DATA" command so i can't implement this solution. In any case the only way to validate a mail at 100% is to send a confirmation email. This pkg is complementary/in addition, to avoid sending too much emails confirmation to wrong emails in limiting with the validation.

masnun commented 7 years ago

Could you please tell me how you got 554 delivery error: dd This user doesn't have a yahoo.com account? How can I reproduce the same message?

badoux commented 7 years ago

root@root$ nslookup -q=mx yahoo.com Server: 192.168.1.1 Address: 192.168.1.1#53

Non-authoritative answer: yahoo.com mail exchanger = 1 mta5.am0.yahoodns.net. yahoo.com mail exchanger = 1 mta6.am0.yahoodns.net. yahoo.com mail exchanger = 1 mta7.am0.yahoodns.net.

Authoritative answers can be found from:

root@root$ telnet mta5.am0.yahoodns.net 25 Trying 98.138.112.38... Connected to mta5.am0.yahoodns.net. Escape character is '^]'. 220 mta1086.mail.ne1.yahoo.com ESMTP ready helo you 250 mta1086.mail.ne1.yahoo.com mail from: me@me.com 250 sender me@me.com ok rcpt to: 28798789798789797@yahoo.com 250 recipient 28798789798789797@yahoo.com ok DATA 354 go ahead FROM: me@me.com TO: 28798789798789797@yahoo.com Subject: / . 554 delivery error: dd This user doesn't have a yahoo.com account (28798789798789797@yahoo.com) [0] - mta1086.mail.ne1.yahoo.com

badoux commented 7 years ago

you can use https://golang.org/pkg/net/smtp/#Client.Data, like this =>

func ValidateHost(email string) error {
    _, host := split(email)
    mx, err := net.LookupMX(host)
    if err != nil {
        return ErrUnresolvableHost
    }

    client, err := smtp.Dial(fmt.Sprintf("%s:%d", mx[0].Host, 25))
    if err != nil {
        return NewSmtpError(err)
    }
    defer client.Close()
    err = client.Hello("checkmail.me")
    if err != nil {
        return NewSmtpError(err)
    }
    err = client.Mail("checkmail@gmail.com")
    if err != nil {
        return NewSmtpError(err)
    }
    err = client.Rcpt(email)
    if err != nil {
        return NewSmtpError(err)
    }
    w, err := client.Data()
    if err != nil {
        return NewSmtpError(err)
    }
    _, err = w.Write([]byte("/"))
    if err != nil {
        return NewSmtpError(err)
    }
    err = w.Close()
    if err != nil {
        return NewSmtpError(err)
    }
    return nil
}

but this is sending an email from checkmail@gmail.com to the given email ;)

masnun commented 7 years ago

I tried data call in the past but didn't manage it. I will try it again. Thanks for the help.

masnun commented 7 years ago

Thanks a lot. It worked.