-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.go
More file actions
43 lines (37 loc) · 1.1 KB
/
send_email.go
File metadata and controls
43 lines (37 loc) · 1.1 KB
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
package msgraph
// Http202 captures the response from API calls that return a 202 status code.
type Http202 struct {
Content string `json:"content"`
}
// SendEmail sends an email using Microsoft Graph API
func (c *Client) SendEmail(subject, body string, contentType ContentType, saveSentItems bool, toRecipients, ccRecipients, bccRecipients []string, attachs []Attachment) error {
emailData := SendMailRequest{
Message: Message{
Subject: subject,
Body: Body{
ContentType: contentType.String(),
Content: body,
},
ToRecipients: SetRecipients(toRecipients),
CcRecipients: SetRecipients(ccRecipients),
BccRecipients: SetRecipients(bccRecipients),
Attachments: attachs,
},
SaveToSentItems: saveSentItems,
}
var response Http202
err := c.Post("/me/sendMail", emailData, nil, &response)
return err
}
func SetRecipients(recipients []string) []Recipient {
result := make([]Recipient, 0)
for _, recipient := range recipients {
if recipient != "" {
result = append(result, Recipient{
EmailAddress: EmailAddress{
Address: recipient,
}})
}
}
return result
}