-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (48 loc) · 1.45 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"os"
"strconv"
"gopkg.in/gomail.v2"
)
var (
SmtpUser = os.Args[1]
SmtpPass = os.Args[2]
Host = os.Args[3]
Port = os.Args[4]
CharSet = "UTF-8"
FromEmail = os.Args[5]
ToEmail = os.Args[6]
)
func SendTestMail(sender string, senderName string, recipient string, recipientName string) error {
// Create a new message.
m := gomail.NewMessage()
var emailHTMLBody string
emailHTMLBody = "Hello World Test : From " + SmtpUser
// Set the main email part to use HTML.
m.SetBody("text/html", emailHTMLBody)
// Construct the message headers, including a Configuration Set and a Tag.
m.SetHeaders(map[string][]string{
"From": {m.FormatAddress(sender, senderName)},
"To": {recipient},
"Subject": {"Hello World Test"},
// Comment or remove the next line if you are not using a configuration set
// "X-SES-CONFIGURATION-SET": {ConfigSet},
// Comment or remove the next line if you are not using custom tags
// "X-SES-MESSAGE-TAGS": {Tags},
})
m.SetAddressHeader("Cc", os.Args[1], "Team")
port, _ := strconv.Atoi(Port)
// Send the email.
d := gomail.NewPlainDialer(Host, port, SmtpUser, SmtpPass)
// Display an error message if something goes wrong; otherwise,
// display a message confirming that the message was sent.
if err := d.DialAndSend(m); err != nil {
return err
}
return nil
}
func main() {
err := SendTestMail(FromEmail, "SMTPTestFrom", ToEmail, "SMTPTestTo")
fmt.Println(err)
}