-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.go
44 lines (34 loc) · 903 Bytes
/
mail.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
package main
import (
"log"
"net/smtp"
)
// smtpServer data to smtp server.
type smtpServer struct {
host string
port string
}
// Address URI to smtp server.
func (s *smtpServer) Address() string {
return s.host + ":" + s.port
}
// MailParams contains from, to and message properties
type MailParams struct {
from string
to string
message []byte
}
// SendMail sends an email from norsys account
func SendMail(mailParams *MailParams) (err error) {
// Sender data.
from := "[email protected]"
password := "YOUR-GMAIL-PASSWORD"
// smtp server configuration.
smtpServer := smtpServer{host: "smtp.gmail.com", port: "587"}
// Authentication.
auth := smtp.PlainAuth("", from, password, smtpServer.host)
// Sending email.
err = smtp.SendMail(smtpServer.Address(), auth, from, []string{mailParams.to}, mailParams.message)
log.Print("Email processed")
return err
}