add simple mailer
This commit is contained in:
parent
3d0e3f212c
commit
72d8862371
|
@ -0,0 +1,27 @@
|
|||
package mailer
|
||||
|
||||
import (
|
||||
"net/smtp"
|
||||
)
|
||||
|
||||
type Mailer struct {
|
||||
server string
|
||||
port string
|
||||
auth smtp.Auth
|
||||
from string
|
||||
}
|
||||
|
||||
func NewMailer(server, port, username, password string) Mailer {
|
||||
auth := smtp.PlainAuth("", username, password, server)
|
||||
return Mailer{
|
||||
server: server,
|
||||
port: port,
|
||||
auth: auth,
|
||||
from: username,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mailer) SendMail(to []string, msg string) (err error) {
|
||||
err = smtp.SendMail(m.server+":"+m.port, m.auth, m.from, to, []byte(msg))
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue