newemailer for defaults
parent
0fd98c91a6
commit
90cb736ede
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bytbox/go-pop3"
|
"github.com/bytbox/go-pop3"
|
||||||
|
|
@ -22,6 +23,20 @@ type Emailer struct {
|
||||||
Limit int
|
Limit int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewEmailer() *Emailer {
|
||||||
|
envOr := func(key, def string) string {
|
||||||
|
if v, ok := os.LookupEnv(strings.ToUpper(key)); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
return &Emailer{
|
||||||
|
From: envOr("FROM", "breellocaldev@gmail.com"),
|
||||||
|
SMTP: envOr("SMTP", "smtp.gmail.com:465"),
|
||||||
|
Password: envOr("PASSWORD", "ML3WQRFSqe9rQ8qNkm"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Emailer) Read() (chan *mail.Message, error) {
|
func (e *Emailer) Read() (chan *mail.Message, error) {
|
||||||
return e.ReadIMAP()
|
return e.ReadIMAP()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
main.go
7
main.go
|
|
@ -6,14 +6,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
emailer := contact.NewEmailer()
|
||||||
as := args.NewArgSet()
|
as := args.NewArgSet()
|
||||||
as.Append(args.STRING, "to", "email destination", "squeaky2x3@gmail.com")
|
as.Append(args.STRING, "to", "email destination", "squeaky2x3@gmail.com")
|
||||||
as.Append(args.STRING, "subject", "message subject", "go emailer")
|
as.Append(args.STRING, "subject", "message subject", "go emailer")
|
||||||
as.Append(args.STRING, "body", "message content", "go emailer")
|
as.Append(args.STRING, "body", "message content", "go emailer")
|
||||||
as.Append(args.STRING, "from", "message sender", "breellocaldev@gmail.com")
|
|
||||||
as.Append(args.STRING, "password", "message sender password", "ML3WQRFSqe9rQ8qNkm")
|
|
||||||
as.Append(args.STRING, "smtp", "smtp server:port", "smtp.gmail.com:465")
|
|
||||||
as.Append(args.STRING, "pop3", "pop3 server:port", "pop.gmail.com:995")
|
as.Append(args.STRING, "pop3", "pop3 server:port", "pop.gmail.com:995")
|
||||||
|
as.Append(args.STRING, "password", "message sender password", emailer.Password)
|
||||||
|
as.Append(args.STRING, "from", "message sender", emailer.From)
|
||||||
|
as.Append(args.STRING, "smtp", "smtp server:port", emailer.SMTP)
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue