Skip to content

Instantly share code, notes, and snippets.

@maisarissi
Created May 2, 2023 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maisarissi/ca439f6541511b1e8bf695e67ca6c24f to your computer and use it in GitHub Desktop.
Save maisarissi/ca439f6541511b1e8bf695e67ca6c24f to your computer and use it in GitHub Desktop.
microsoftgraph-go-v1-send-mail
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