-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
78 lines (62 loc) · 1.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/docopt/docopt-go"
)
func main() {
usage := `mail-bouncer 1.0
mail-bouncer is email validation service with simple RESTish API.
Example:
> curl -i ":8080/[email protected]"
HTTP/1.1 200 OK
{
"email":"[email protected]",
"is_valid":false,
"description":"MX server is unreachable",
"error":"can't connect to email.com: ...."
}
> curl -i "http://127.0.0.1:8080/[email protected]"
HTTP/1.1 200 OK
> curl -i "http://127.0.0.1:8080/[email protected]&callback=$URL"
HTTP/1.1 201 Created
And POST to $URL with json data, ex.:
{
"email": "[email protected]",
"valid": false,
"error": "RCPT failed for [email protected]: 554 5.7.1 Helo command rejected"
}
Usage:
mail-bouncer [options]
mail-bouncer -v | -h
Options:
-h --help Show this screen.
-v --version Show version.
--listen=<listen> Host and port for http interface
--host=<host> Hostname for HELO command
--from=<from> Email address for MAIL command
`
args, err := docopt.Parse(usage, nil, true, "mail-bouncer 1.0", false)
if err != nil {
log.Fatal(err)
}
listen := ":8080"
if args["--listen"] != nil {
listen = args["--listen"].(string)
}
mailHostname := "localhost"
if args["--host"] != nil {
mailHostname = args["--host"].(string)
}
fromAddress := "tester@localhost"
if args["--from"] != nil {
fromAddress = args["--from"].(string)
}
http.Handle("/", NewHandler(mailHostname, fromAddress))
log.WithFields(log.Fields{
"pid": os.Getpid(),
"listen": listen,
}).Info("Ready")
log.Fatal(http.ListenAndServe(listen, nil))
}