feat: send mail
This commit is contained in:
33
mailer/send.go
Normal file
33
mailer/send.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package mailer
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/smtp"
|
||||
|
||||
"github.com/jordan-wright/email"
|
||||
)
|
||||
|
||||
func (s Service) Send(m Mail) (err error) {
|
||||
e := email.NewEmail()
|
||||
e.To = []string{m.TO}
|
||||
e.Bcc = []string{"niklas@sunway.ch"}
|
||||
e.From = s.from
|
||||
e.Subject = m.Subject
|
||||
e.Text = []byte(m.Body)
|
||||
|
||||
for _, a := range m.Attachments {
|
||||
e.Attach(a.Content, a.Name, a.MimeType)
|
||||
}
|
||||
err = e.SendWithTLS(s.cfg.SMTP.Host+":"+s.cfg.SMTP.Port, smtp.PlainAuth(
|
||||
s.cfg.SMTP.User,
|
||||
s.cfg.SMTP.User,
|
||||
s.cfg.SMTP.Password,
|
||||
s.cfg.SMTP.Host,
|
||||
), &tls.Config{
|
||||
ServerName: s.cfg.SMTP.Host,
|
||||
})
|
||||
|
||||
// err = s.pool.Send(e, time.Second*5)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user