Semaphore/util/mail.go
2017-04-18 15:36:09 +01:00

30 lines
434 B
Go

package util
import (
"bytes"
"net/smtp"
)
func SendMail(emailHost, mailSender, mailRecipient string, mail bytes.Buffer) error {
c, err := smtp.Dial(emailHost)
if err != nil {
return err
}
defer c.Close()
// Set the sender and recipient.
c.Mail(mailSender)
c.Rcpt(mailRecipient)
// Send the email body.
wc, err := c.Data()
if err != nil {
return err
}
defer wc.Close()
_, err = mail.WriteTo(wc)
return err
}