You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
667 B
34 lines
667 B
package message
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/jordan-wright/email"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/smtp"
|
|
)
|
|
|
|
type Mail struct {
|
|
Host string
|
|
Protocol string
|
|
Port int
|
|
Username string
|
|
Password string
|
|
FromName string
|
|
To []string
|
|
}
|
|
|
|
func (m *Mail) Send(body Body) {
|
|
log.Printf("[mail] sending message...")
|
|
e := email.NewEmail()
|
|
e.From = m.FromName
|
|
e.To = m.To
|
|
e.Subject = body.Title
|
|
e.Text = []byte(body.Content)
|
|
addr := fmt.Sprintf("%v:%v", m.Host, m.Port)
|
|
err := e.Send(addr, smtp.PlainAuth("", m.Username, m.Password, m.Host))
|
|
if err != nil {
|
|
log.Fatalf("[mail] send failed: %v\n", err)
|
|
}
|
|
log.Printf("[mail] send successful")
|
|
}
|