feat: send mail
This commit is contained in:
52
mailer/resource.go
Normal file
52
mailer/resource.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package mailer
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/jordan-wright/email"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
SMTP SMTPConfig
|
||||
From string
|
||||
}
|
||||
|
||||
type SMTPConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
from string
|
||||
pool *email.Pool
|
||||
cfg Config
|
||||
}
|
||||
|
||||
func New(cfg Config) (s *Service, err error) {
|
||||
p, err := email.NewPool(
|
||||
cfg.SMTP.Host+":"+cfg.SMTP.Port,
|
||||
1,
|
||||
smtp.PlainAuth(
|
||||
"",
|
||||
cfg.SMTP.User,
|
||||
cfg.SMTP.Password,
|
||||
cfg.SMTP.Host,
|
||||
), &tls.Config{
|
||||
InsecureSkipVerify: true, // set false in production
|
||||
ServerName: cfg.SMTP.Host, // must match the SMTP host
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
s = &Service{
|
||||
from: cfg.From,
|
||||
pool: p,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user