-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
44 lines (34 loc) · 857 Bytes
/
main.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 (
"fmt"
"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
}
func main() {
// Sender data.
from := "youremail@gmail.com"
password := "yourSecretPassword"
// Receiver email address.
to := []string{"firstemail@gmail.com", "secondemail@gmail.com"}
// smtp server configuration.
smtpServer := smtpServer{host: "smtp.gmail.com", port: "587"}
// Message.
message := []byte("This is a really unimaginative message, I know.")
// Authentication.
auth := smtp.PlainAuth("", from, password, smtpServer.host)
// Sending email.
err := smtp.SendMail(smtpServer.Address(), auth, from, to, message)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Email Sent!")
}