Created
September 9, 2016 22:42
-
-
Save ransford/a65bab1cf4c8232e602b74af28eaa4f4 to your computer and use it in GitHub Desktop.
email verify in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Run like: | |
go run <host> <address> | |
*/ | |
package main | |
import ( | |
"fmt" | |
"net/smtp" | |
"os" | |
) | |
func usage() { | |
fmt.Printf("Usage: %s <address>\n", os.Args[0]) | |
} | |
func main() { | |
args := os.Args[1:] | |
if len(args) != 2 { | |
usage() | |
os.Exit(1) | |
} | |
host := fmt.Sprintf("%s:25", args[0]) | |
address := args[1] | |
cli, err := smtp.Dial(host) | |
if err != nil { | |
fmt.Println("Error", err) | |
os.Exit(0) | |
} | |
merr := cli.Mail("[email protected]") | |
if merr != nil { | |
fmt.Println("Error", merr) | |
os.Exit(0) | |
} | |
rcpterr := cli.Rcpt(address) | |
if rcpterr != nil { | |
fmt.Printf("Address %s is probably invalid\n", address) | |
fmt.Printf("(Server said: %s)\n", rcpterr) | |
os.Exit(0) | |
} else { | |
fmt.Printf("Address %s was valid!\n", address) | |
} | |
reseterr := cli.Reset() | |
if reseterr != nil { | |
fmt.Println("Error", reseterr) | |
os.Exit(0) | |
} | |
qerr := cli.Quit() | |
if qerr != nil { | |
fmt.Println("Error", qerr) | |
os.Exit(0) | |
} | |
cli.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops, error in Usage string; should be: