Created
May 2, 2023 20:19
-
-
Save maisarissi/ca439f6541511b1e8bf695e67ca6c24f to your computer and use it in GitHub Desktop.
microsoftgraph-go-v1-send-mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (g *GraphHelper) SendMail() error { | |
message := models.NewMessage() | |
subject := "Meet for lunch?" | |
content := "The new cafeteria is open." | |
body := models.NewItemBody() | |
message.SetSubject(&subject) | |
message.SetBody(body) | |
contentType := models.TEXT_BODYTYPE | |
body.SetContentType(&contentType) | |
body.SetContent(&content) | |
toRecipient := models.NewRecipient() | |
toEmailAddress := models.NewEmailAddress() | |
toAddress := "admin@M365x18467905.onmicrosoft.com" | |
toEmailAddress.SetAddress(&toAddress) | |
toRecipient.SetEmailAddress(toEmailAddress) | |
toRecipients := []models.Recipientable{ | |
toRecipient, | |
} | |
message.SetToRecipients(toRecipients) | |
ccRecipient := models.NewRecipient() | |
ccEmailAddress := models.NewEmailAddress() | |
ccAddress := "admin@M365x18467905.onmicrosoft.com" | |
ccEmailAddress.SetAddress(&ccAddress) | |
ccRecipient.SetEmailAddress(ccEmailAddress) | |
ccRecipients := []models.Recipientable{ | |
ccRecipient, | |
} | |
message.SetCcRecipients(ccRecipients) | |
requestBody := users.NewItemSendMailPostRequestBody() | |
requestBody.SetMessage(message) | |
saveToSentItems := false | |
requestBody.SetSaveToSentItems(&saveToSentItems) | |
err := g.prodClient.Me().SendMail().Post(context.Background(), requestBody, nil) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment