-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmail.go
More file actions
42 lines (32 loc) · 1.02 KB
/
mail.go
File metadata and controls
42 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package g
import (
"crypto/tls"
"os"
"gopkg.in/gomail.v2"
)
// AlertEmail is the email address to send errors to
var AlertEmail = os.Getenv("ALERT_EMAIL")
// SMTPServer is email SMTP server host
var SMTPServer = "smtp.gmail.com"
// SMTPPort is email SMTP server port
var SMTPPort = 465
// SMTPUser is SMTP user name
var SMTPUser = os.Getenv("SMTP_USER")
// SMTPPass is user password
var SMTPPass = os.Getenv("SMTP_PASSWORD")
// SendMail sends an email to the specific email address
// https://godoc.org/gopkg.in/gomail.v2#example-package
func SendMail(from string, to []string, subject string, textHTML string) error {
m := gomail.NewMessage()
m.SetHeader("From", from)
m.SetHeader("To", to...)
// m.SetAddressHeader("Cc", "dan@example.com", "Dan")
m.SetHeader("Subject", subject)
m.SetBody("text/html", textHTML)
// m.Attach("/home/Alex/lolcat.jpg")
d := gomail.NewDialer(SMTPServer, SMTPPort, SMTPUser, SMTPPass)
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
// Send the email
err := d.DialAndSend(m)
return err
}