revert last commit, meant for heroku branch
This commit is contained in:
parent
13d31c62a6
commit
3b11f37162
3 changed files with 41 additions and 75 deletions
101
email/email.go
101
email/email.go
|
|
@ -3,7 +3,6 @@ package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -13,10 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sendgrid/sendgrid-go"
|
"github.com/go-mail/mail"
|
||||||
"github.com/sendgrid/sendgrid-go/helpers/mail"
|
|
||||||
|
|
||||||
// "github.com/go-mail/mail"
|
|
||||||
"github.com/jaytaylor/html2text"
|
"github.com/jaytaylor/html2text"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/vanng822/go-premailer/premailer"
|
"github.com/vanng822/go-premailer/premailer"
|
||||||
|
|
@ -29,7 +25,7 @@ var (
|
||||||
|
|
||||||
// Mailer is a SMTP mailer.
|
// Mailer is a SMTP mailer.
|
||||||
type Mailer struct {
|
type Mailer struct {
|
||||||
client *sendgrid.Client
|
client *mail.Dialer
|
||||||
from Email
|
from Email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,49 +35,35 @@ func NewMailer() (*Mailer, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// usage with sendgrid api key client
|
smtp := struct {
|
||||||
apiKey := viper.GetString("SENDGRID_API_KEY")
|
Host string
|
||||||
if apiKey == "" {
|
Port int
|
||||||
return nil, errors.New("missing sendgrid api key")
|
User string
|
||||||
|
Password string
|
||||||
|
}{
|
||||||
|
viper.GetString("email_smtp_host"),
|
||||||
|
viper.GetInt("email_smtp_port"),
|
||||||
|
viper.GetString("email_smtp_user"),
|
||||||
|
viper.GetString("email_smtp_password"),
|
||||||
}
|
}
|
||||||
client := sendgrid.NewSendClient(apiKey)
|
|
||||||
|
|
||||||
mailer := &Mailer{
|
s := &Mailer{
|
||||||
client: client,
|
client: mail.NewPlainDialer(smtp.Host, smtp.Port, smtp.User, smtp.Password),
|
||||||
from: NewEmail(viper.GetString("email_from_name"), viper.GetString("email_from_address")),
|
from: NewEmail(viper.GetString("email_from_name"), viper.GetString("email_from_address")),
|
||||||
}
|
}
|
||||||
return mailer, nil
|
|
||||||
|
|
||||||
// usage with go-mail basic smtp auth client
|
if smtp.Host == "" {
|
||||||
// smtp := struct {
|
log.Println("SMTP host not set => printing emails to stdout")
|
||||||
// Host string
|
debug = true
|
||||||
// Port int
|
return s, nil
|
||||||
// User string
|
}
|
||||||
// Password string
|
|
||||||
// }{
|
|
||||||
// viper.GetString("email_smtp_host"),
|
|
||||||
// viper.GetInt("email_smtp_port"),
|
|
||||||
// viper.GetString("email_smtp_user"),
|
|
||||||
// viper.GetString("email_smtp_password"),
|
|
||||||
// }
|
|
||||||
|
|
||||||
// s := &Mailer{
|
d, err := s.client.Dial()
|
||||||
// client: mail.NewDialer(smtp.Host, smtp.Port, smtp.User, smtp.Password),
|
if err == nil {
|
||||||
// from: NewEmail(viper.GetString("email_from_name"), viper.GetString("email_from_address")),
|
d.Close()
|
||||||
// }
|
return s, nil
|
||||||
|
}
|
||||||
// if smtp.Host == "" {
|
return nil, err
|
||||||
// log.Println("SMTP host not set => printing emails to stdout")
|
|
||||||
// debug = true
|
|
||||||
// return s, nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
// d, err := s.client.Dial()
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// d.Close()
|
|
||||||
// return s, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send sends the mail via smtp.
|
// Send sends the mail via smtp.
|
||||||
|
|
@ -93,33 +75,14 @@ func (m *Mailer) Send(email *message) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// usage with sendgrid
|
msg := mail.NewMessage()
|
||||||
from := mail.NewEmail(email.from.Name, email.from.Address)
|
msg.SetAddressHeader("From", email.from.Address, email.from.Name)
|
||||||
to := mail.NewEmail(email.to.Name, email.to.Address)
|
msg.SetAddressHeader("To", email.to.Address, email.to.Name)
|
||||||
message := mail.NewSingleEmail(from, email.subject, to, email.text, email.html)
|
msg.SetHeader("Subject", email.subject)
|
||||||
|
msg.SetBody("text/plain", email.text)
|
||||||
|
msg.AddAlternative("text/html", email.html)
|
||||||
|
|
||||||
response, err := m.client.Send(message)
|
return m.client.DialAndSend(msg)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if debug {
|
|
||||||
log.Println(response.StatusCode)
|
|
||||||
log.Println(response.Body)
|
|
||||||
log.Println(response.Headers)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
// usage with go-mail
|
|
||||||
// msg := mail.NewMessage()
|
|
||||||
// msg.SetAddressHeader("From", email.from.Address, email.from.Name)
|
|
||||||
// msg.SetAddressHeader("To", email.to.Address, email.to.Name)
|
|
||||||
// msg.SetHeader("Subject", email.subject)
|
|
||||||
// msg.SetBody("text/plain", email.text)
|
|
||||||
// msg.AddAlternative("text/html", email.html)
|
|
||||||
|
|
||||||
// return m.client.DialAndSend(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// message struct holds all parts of a specific email message.
|
// message struct holds all parts of a specific email message.
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -10,6 +10,7 @@ require (
|
||||||
github.com/go-chi/docgen v1.0.5
|
github.com/go-chi/docgen v1.0.5
|
||||||
github.com/go-chi/jwtauth v4.0.4+incompatible
|
github.com/go-chi/jwtauth v4.0.4+incompatible
|
||||||
github.com/go-chi/render v1.0.1
|
github.com/go-chi/render v1.0.1
|
||||||
|
github.com/go-mail/mail v2.3.1+incompatible
|
||||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
|
||||||
github.com/go-pg/migrations v6.2.0+incompatible
|
github.com/go-pg/migrations v6.2.0+incompatible
|
||||||
github.com/go-pg/pg v7.1.7+incompatible
|
github.com/go-pg/pg v7.1.7+incompatible
|
||||||
|
|
@ -24,8 +25,6 @@ require (
|
||||||
github.com/olekukonko/tablewriter v0.0.4 // indirect
|
github.com/olekukonko/tablewriter v0.0.4 // indirect
|
||||||
github.com/onsi/gomega v1.4.2 // indirect
|
github.com/onsi/gomega v1.4.2 // indirect
|
||||||
github.com/pelletier/go-toml v1.6.0 // indirect
|
github.com/pelletier/go-toml v1.6.0 // indirect
|
||||||
github.com/sendgrid/rest v2.6.2+incompatible // indirect
|
|
||||||
github.com/sendgrid/sendgrid-go v3.7.1+incompatible
|
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.4.2
|
||||||
github.com/spf13/afero v1.2.2 // indirect
|
github.com/spf13/afero v1.2.2 // indirect
|
||||||
github.com/spf13/cast v1.3.1 // indirect
|
github.com/spf13/cast v1.3.1 // indirect
|
||||||
|
|
@ -40,7 +39,9 @@ require (
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
|
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
|
||||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
|
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
|
||||||
golang.org/x/text v0.3.2 // indirect
|
golang.org/x/text v0.3.2 // indirect
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
gopkg.in/ini.v1 v1.52.0 // indirect
|
gopkg.in/ini.v1 v1.52.0 // indirect
|
||||||
|
gopkg.in/mail.v2 v2.3.1 // indirect
|
||||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||||
mellium.im/sasl v0.2.1 // indirect
|
mellium.im/sasl v0.2.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
10
go.sum
10
go.sum
|
|
@ -45,6 +45,8 @@ github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1
|
||||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
|
github.com/go-mail/mail v2.3.1+incompatible h1:UzNOn0k5lpfVtO31cK3hn6I4VEVGhe3lX8AJBAxXExM=
|
||||||
|
github.com/go-mail/mail v2.3.1+incompatible/go.mod h1:VPWjmmNyRsWXQZHVHT3g0YbIINUkSmuKOiLIDkWbL6M=
|
||||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
|
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
|
||||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||||
github.com/go-pg/migrations v6.2.0+incompatible h1:OCaoPbrTHwyd+zgWbbhVZyZ8CekfD2xbtap7BZAb27Q=
|
github.com/go-pg/migrations v6.2.0+incompatible h1:OCaoPbrTHwyd+zgWbbhVZyZ8CekfD2xbtap7BZAb27Q=
|
||||||
|
|
@ -139,10 +141,6 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
|
||||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sendgrid/rest v2.6.2+incompatible h1:zGMNhccsPkIc8SvU9x+qdDz2qhFoGUPGGC4mMvTondA=
|
|
||||||
github.com/sendgrid/rest v2.6.2+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
|
|
||||||
github.com/sendgrid/sendgrid-go v3.7.1+incompatible h1:Pw98qJ7CvR7I5vVlV3CnA+OofRBkAxxR9sgsPX0qEoY=
|
|
||||||
github.com/sendgrid/sendgrid-go v3.7.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||||
|
|
@ -247,6 +245,8 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||||
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
@ -256,6 +256,8 @@ gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
|
||||||
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/ini.v1 v1.52.0 h1:j+Lt/M1oPPejkniCg1TkWE2J3Eh1oZTsHSXzMTzUXn4=
|
gopkg.in/ini.v1 v1.52.0 h1:j+Lt/M1oPPejkniCg1TkWE2J3Eh1oZTsHSXzMTzUXn4=
|
||||||
gopkg.in/ini.v1 v1.52.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.52.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk=
|
||||||
|
gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw=
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue