initial
This commit is contained in:
commit
dd652ab74d
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module git.icod.de/essentials/mailer
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require github.com/go-mail/mail v2.3.1+incompatible
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
github.com/go-mail/mail v2.3.1+incompatible h1:UzNOn0k5lpfVtO31cK3hn6I4VEVGhe3lX8AJBAxXExM=
|
||||||
|
github.com/go-mail/mail v2.3.1+incompatible/go.mod h1:VPWjmmNyRsWXQZHVHT3g0YbIINUkSmuKOiLIDkWbL6M=
|
38
mailer.go
Normal file
38
mailer.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package mailer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
|
||||||
|
"github.com/go-mail/mail"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
From string
|
||||||
|
Host string
|
||||||
|
Port int
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mailer struct {
|
||||||
|
dialer *mail.Dialer
|
||||||
|
options *Options
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(options *Options) *Mailer {
|
||||||
|
dialer := mail.NewDialer(options.Host, options.Port, options.Username, options.Password)
|
||||||
|
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
|
return &Mailer{
|
||||||
|
dialer: dialer,
|
||||||
|
options: options,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mailer *Mailer) Send(to, subject, text string) error {
|
||||||
|
m := mail.NewMessage()
|
||||||
|
m.SetHeader("From", mailer.options.From)
|
||||||
|
m.SetHeader("To", to)
|
||||||
|
m.SetHeader("Subject", subject)
|
||||||
|
m.SetBody("text/plain", text)
|
||||||
|
return mailer.dialer.DialAndSend(m)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user