Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func CheckMails(mails []string) []string {
- var existingMails []string
- fmt.Printf("!!!!!!!!!!!!!!STARTING!!!!!!!!!!!! %s nnn", mails[1])
- for i := 0; i < len(mails); i++ {
- err := validateHost(mails[i])
- if err != nil {
- fmt.Printf("Error validating host. %s", err)
- }
- smtpErr, ok := err.(checkmail.SmtpError)
- if ok {
- fmt.Printf("Code: %s, Msg: %s", smtpErr.Code(), smtpErr)
- if smtpErr.Code() == "dia" {
- break
- }
- } else {
- fmt.Println("Email exists")
- existingMails = append(existingMails, mails[i])
- }
- }
- fmt.Printf("!!!!!!!!!!!!!!ENDING!!!!!!!!!!!! %s nnn", mails[1])
- return existingMails
- }
- func validateHost(email string) error {
- _, host := split(email)
- mx, err := net.LookupMX(host)
- if err != nil {
- fmt.Printf("Error, UnresolvableHost! %s", err)
- }
- client, err := smtp.Dial(fmt.Sprintf("%s:%d", mx[0].Host, 25))
- // fmt.Println(client)
- defer client.Close()
- if err != nil {
- //fmt.Println(client)
- //log.Fatalln(err)
- fmt.Printf("SmtpError! %s n", err)
- }
- t := time.AfterFunc(forceDisconnectAfter, func() { client.Close() })
- defer t.Stop()
- // t := NewTimer(10, func() { client.Close() })
- // defer t.Stop()
- err = client.Hello("checkmail.me")
- //err = client.Hello("gmail.com")
- // fmt.Println(client)
- if err != nil {
- //log.Fatalln(err)
- fmt.Printf("client.Hello SmtpError! %s n", err)
- }
- err = client.Mail("lansome-cowboy@gmail.com")
- if err != nil {
- fmt.Printf("client.MailSmtpError! %s n", err)
- }
- err = client.Rcpt(email)
- if err != nil {
- fmt.Printf("client.Rcpt SmtpError! %s n", err)
- }
- return nil
- }
- // CheckMailsWithExpectedInterval want to get expectected number of seconds which you are ready to wait while
- // the mail trys to be validated (this time is for ONE mail, slice could have a lot of mails to check)
- // and slice of mails which should be validated
- func CheckMailsWithExpectedInterval(expectedSec int, mails []string) (ok bool, existingMails []string) {
- done := make(chan struct{})
- t1 := time.Now()
- var eMails []string
- go func() {
- eMails = CheckMails(mails)
- close(done)
- }()
- select {
- case <-done:
- if len(eMails) > 1 {
- ok = false
- } else {
- ok = true
- existingMails = eMails
- }
- case <-time.After(time.Duration(expectedSec) * time.Second):
- }
- fmt.Printf("nTime since:")
- fmt.Println(time.Since(t1))
- return ok, existingMails
- }
- func split(email string) (account, host string) {
- i := strings.LastIndexByte(email, '@')
- account = email[:i]
- host = email[i+1:]
- return
- }
- const forceDisconnectAfter = time.Second * 10
- email1 := []string{
- "andreasId@fromatob.com",
- "Andreas.Wolff@fromatob.com",
- "AndreasWolff@fromatob.com",
- "Wolff.Andreas@fromatob.com",
- "WolffAndreas@fromatob.com",
- "Andreas@fromatob.com,Wolff@fromatob.com",
- "A.Wolff@fromatob.com",
- "AWolff@fromatob.com",
- "Andreas.W@fromatob.com",
- "AndreasW@fromatob.com",
- "Wolff.A@fromatob.com",
- "WolffA@fromatob.com",
- "W.Andreas@fromatob.com",
- "WAndreas@fromatob.com",
- }
- panic: runtime error: invalid memory address or nil pointer dereference
- [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x84fefa]
- goroutine 260 [running]:
- net/smtp.(*Client).Close(0x0, 0x0, 0x0)
- /usr/lib/go-1.10/src/net/smtp/smtp.go:76 +0x2a
- panic(0x90a360, 0xb94ae0)
- /usr/lib/go-1.10/src/runtime/panic.go:502 +0x24a
- net/smtp.(*Client).Hello(0x0, 0x97d912, 0x9, 0x0, 0x0)
- /usr/lib/go-1.10/src/net/smtp/smtp.go:100 +0x78
- magictool/mailchecker.validateHost(0xc4204c7020, 0x23, 0x0, 0x0)
- /home/username/go/src/magictool/mailchecker/mailchecker.go:115 +0x749
- magictool/mailchecker.CheckMails(0xc4201c0000, 0xf, 0xf, 0x0, 0x0, 0x0)
- /home/username/go/src/magictool/mailchecker/mailchecker.go:20 +0x1d1
- magictool/mailchecker.CheckMailsWithExpectedInterval.func1(0xc4201c0000, 0xf, 0xf, 0xc42038f5c0, 0xc4203b7ec0)
- /home/username/go/src/magictool/mailchecker/mailchecker.go:49 +0x3f
- created by magictool/mailchecker.CheckMailsWithExpectedInterval
- /home/username/go/src/magictool/mailchecker/mailchecker.go:48 +0x12c
Add Comment
Please, Sign In to add comment