mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-24 22:06:43 +01:00
30 lines
434 B
Go
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
|
|
}
|