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
672 B

package message
import (
"fmt"
"github.com/jordan-wright/email"
"net/smtp"
"sendmsg/common"
)
type Mail struct {
Host string
Protocol string
Port int
Username string
Password string
FromName string
To []string
}
func (m *Mail) Send(body Body) {
common.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 {
common.Log.Fatalf("[mail] send failed: %v\n", err)
}
common.Log.Printf("[mail] send successful")
}