-
Notifications
You must be signed in to change notification settings - Fork 1
/
smtp.go
45 lines (40 loc) · 965 Bytes
/
smtp.go
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
43
44
45
package main
import (
"fmt"
"github.com/jpoehls/gophermail"
"log"
"net/mail"
"net/smtp"
"time"
)
func SendEmailSMTP(address, subject, plain, html string) {
// Set up authentication information
auth := smtp.PlainAuth(
"",
c.Config.Integrations.SMTP.Login,
c.Config.Integrations.SMTP.Password,
c.Config.Integrations.SMTP.Hostname,
)
from := mail.Address{Address: c.Config.Integrations.SMTP.Sender}
to := mail.Address{Address: address}
headers := mail.Header{}
headers["Date"] = []string{time.Now().Format(time.RFC822Z)}
message := &gophermail.Message{
From: from,
To: []mail.Address{to},
Subject: subject,
Body: plain,
HTMLBody: html,
Headers: headers,
}
// Connect to the server, auth and send
host := fmt.Sprintf("%s:%d", c.Config.Integrations.SMTP.Hostname, c.Config.Integrations.SMTP.Port)
err := gophermail.SendMail(
host,
auth,
message,
)
if err != nil {
log.Println("SMTP-Error:", err)
}
}