func (m *SmtpMail) SendMail(addr string, a smtp.Auth, from string, to []string, subject string, msg []byte) error {
	log.Println("Sending Email:", subject)
	log.Println("Email Server:", addr)

	toAddress := make([]mail.Address, 1)
	toAddress[0].Address = to[0]

	message := gophermail.Message{}
	message.To = toAddress
	message.SetFrom(from)
	message.Subject = subject
	message.HTMLBody = string(msg)

	return gophermail.SendMail(addr, a, &message)
}
Esempio n. 2
0
// CreateMail constructs a message to remind the user of a task due task.
func CreateMail(t server.Task, u server.User, fromAddress string) (*gmail.Message, error) {
	m := new(gmail.Message)
	if err := m.SetFrom(fromAddress); err != nil {
		return nil, err
	}
	if err := m.AddTo(u.Address); err != nil {
		return nil, err
	}
	//TODO list email headers (http://www.jamesshuggins.com/h/web1/list-email-headers.htm)
	//TODO Prefix config option
	m.Subject = fmt.Sprintf("Task Due: %s", t.Name)
	//TODO Generate mail text from a text/template
	m.Body = fmt.Sprintf(`Hya, %s!
The following task needs to be done as soon as possible:

%s
%s

Get to it, ninja!
`, u.Name, t.Name, t.Description)
	return m, nil
}