-
Notifications
You must be signed in to change notification settings - Fork 5
/
ews.go
66 lines (59 loc) · 1.29 KB
/
ews.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
63
64
65
66
package main
import (
"fmt"
"log"
"os"
"github.com/gunsluo/goews/v2"
)
func main() {
c, err := goews.NewClient(
goews.Config{
Address: "https://outlook.office365.com/EWS/Exchange.asmx",
Username: "email@exchangedomain",
Password: "password",
Dump: true,
NTLM: false,
Domain: "",
SkipTLS: false,
},
)
if err != nil {
log.Fatal("->: ", err.Error())
}
filename := "a.txt"
content, err := os.ReadFile(filename)
if err != nil {
log.Fatal("read file: ", err.Error())
}
htmlBody := `<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple HTML document</title>
</head>
<body>
<h1>The email body, as html!</h1>
</body>
</html>`
err = c.SendEmail(
goews.SendEmailParams{
From: "email@exchangedomain",
To: []string{"ji.luo@target-energysolutions.com"},
Cc: []string{"junkun.ren@target-energysolutions.com"},
Bcc: []string{"Dongsheng.liu@target-energysolutions.com"},
Subject: "An email subject",
Body: htmlBody,
BodyType: goews.BodyTypeHtml,
FileAttachments: []goews.AttachmentParams{
{
Name: filename,
ContentType: "",
Size: int64(len(content)),
Content: content,
},
},
})
if err != nil {
log.Fatal("err>: ", err.Error())
}
fmt.Println("--- success ---")
}