add support for sending emails

Change-Id: I9749cda3b997d70271cb4ca709a7cca82a9a0948
This commit is contained in:
dm
2016-06-10 12:57:41 -07:00
committed by sm
parent 227eb4a551
commit 480304bd87
6 changed files with 370 additions and 34 deletions
+16 -2
View File
@@ -55,7 +55,8 @@ import (
const usage = "vaind [init] <dbname>"
type config struct {
Port int
Port int
Insecure bool
Cert string
Key string
@@ -63,6 +64,11 @@ type config struct {
Static string
EmailTimeout time.Duration `envconfig:"email_timeout"`
SMTPHost string `envconfig:"smtp_host"`
SMTPPort int `envconfig:"smtp_port"`
From string
}
func main() {
@@ -101,6 +107,7 @@ func main() {
c := &config{
Port: 4040,
EmailTimeout: 5 * time.Minute,
SMTPPort: 25,
}
if err := envconfig.Process("vain", c); err != nil {
fmt.Fprintf(os.Stderr, "problem processing environment: %v", err)
@@ -114,6 +121,13 @@ func main() {
os.Exit(0)
}
}
m, err := vain.NewEmail(c.From, c.SMTPHost, c.SMTPPort)
if err != nil {
fmt.Fprintf(os.Stderr, "problem initializing mailer: %v", err)
os.Exit(1)
}
hostname := "localhost"
if hn, err := os.Hostname(); err != nil {
log.Printf("problem getting hostname: %v", err)
@@ -122,7 +136,7 @@ func main() {
}
log.Printf("serving at: http://%s:%d/", hostname, c.Port)
sm := http.NewServeMux()
vain.NewServer(sm, db, c.Static, c.EmailTimeout)
vain.NewServer(sm, db, m, c.Static, c.EmailTimeout, c.Insecure)
addr := fmt.Sprintf(":%d", c.Port)
if c.Cert == "" || c.Key == "" {