2017-03-07 08:15:35 +01:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/smtp"
|
|
|
|
)
|
|
|
|
|
2017-03-13 03:30:48 +01:00
|
|
|
func SendMail(emailHost, mailSender, mailRecipient string, mail bytes.Buffer) error {
|
2017-03-07 08:15:35 +01:00
|
|
|
c, err := smtp.Dial(emailHost)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer c.Close()
|
2017-04-18 16:36:09 +02:00
|
|
|
|
2017-03-07 08:15:35 +01:00
|
|
|
// 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()
|
2017-04-18 16:36:09 +02:00
|
|
|
_, err = mail.WriteTo(wc)
|
|
|
|
return err
|
2017-03-07 08:15:35 +01:00
|
|
|
}
|