-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (49 loc) · 1.41 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
package main
import "github.com/go-mail/mail"
import "io/ioutil"
import "os"
import "fmt"
type EmailUser struct {
Username string
Password string
EmailServer string
Port int
}
func BytesToString(data []byte) string {
return string(data[:])
}
func main() {
sender := os.Getenv("SENDER")
receiver := os.Getenv("RECEIVER")
ccUser := os.Getenv("CC_USER")
mailFile := os.Getenv("MAIL_FILE")
attachFile := os.Getenv("MAIL_ATTACHMENT")
smptPort := 587
password := os.Getenv("SMTP_PASSWORD")
prnumber := os.Getenv("PULL_NUMBER")
emailContent, err := ioutil.ReadFile(mailFile)
if ( err != nil ) {
panic(err)
}
str1 := BytesToString(emailContent)
smtpInfo := &EmailUser{
sender,
password,
"smtp.gmail.com",
smptPort}
m := mail.NewMessage()
m.SetHeader("Subject", "Prow Job failed for jet PR" , prnumber)
m.SetHeader("From", sender)
m.SetHeader("To", receiver)
m.SetAddressHeader("Cc", ccUser, "The great")
m.SetBody("text/html", str1)
if ( len(attachFile) > 0 ) {
m.Attach(attachFile)
}
fmt.Println("Server:",smtpInfo.EmailServer, "Port:",smtpInfo.Port, "user:",smtpInfo.Username, "pass:",smtpInfo.Password)
fmt.Println("senderaddress:",sender,"receiveraddress:",receiver,"ccaddress:",ccUser,"attachmentfiles:",attachFile)
d := mail.NewDialer(smtpInfo.EmailServer, smtpInfo.Port, smtpInfo.Username, smtpInfo.Password)
if err = d.DialAndSend(m); err != nil {
panic(err)
}
}