Skip to content

Commit

Permalink
Merge pull request #1 from mypricehealth/daMSGraph-179329646
Browse files Browse the repository at this point in the history
Send Email Capability
  • Loading branch information
robarchibald authored Sep 3, 2021
2 parents ae385fc + 9905cba commit 045365b
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package msgraph

import "time"

// Attachment represents content related to a event, message, or group post.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/Attachment
type Attachment struct {
ContentType string `json:"contentType,omitempty"`
ID string `json:"id,omitempty"`
IsInline bool `json:"isInline,omitempty"`
LastModifiedDateTime time.Time `json:"lastModifiedDateTime,omitempty"`
Name string `json:"name,omitempty"`
Size int32 `json:"size,omitempty"`
}
11 changes: 11 additions & 0 deletions DateTimeTimeZone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package msgraph

import "time"

// DateTimeTimeZone represents the date, time, and timezone for a given time.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/DateTimeTimeZone?view=graph-rest-1.0
type DateTimeTimeZone struct {
DateTime time.Time `json:"dateTime,omitempty"`
TimeZone *time.Location `json:"timeZone,omitempty"`
}
8 changes: 8 additions & 0 deletions Extension.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package msgraph

// Extension is an abstract type to represent an open type extension.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/Extension
type Extension struct {
ID string `json:"id,omitempty"`
}
11 changes: 11 additions & 0 deletions FollowupFlag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package msgraph

// FollowupFlag are flags on a message that display how it should be followed up on.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/FollowupFlag
type FollowupFlag struct {
CompletedDateTime DateTimeTimeZone `json:"completedDateTime,omitempty"`
DueDateTime DateTimeTimeZone `json:"dueDateTime,omitempty"`
FlagStatus string `json:"flagStatus,omitempty"`
StartDateTime DateTimeTimeZone `json:"startDateTime,omitempty"`
}
9 changes: 9 additions & 0 deletions ForwardMessageOptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// Structure to reply to messages.
//
// See https://docs.microsoft.com/en-us/graph/api/message-reply
type ForwardMessageOptions struct {
Comment string `json:"comment,omitempty"` // A comment to add.
ToRecipients []Recipient `json:"toRecipients,omitempty"` // Properties to be updated when repling.
}
26 changes: 26 additions & 0 deletions GraphClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,32 @@ func (g *GraphClient) CreateUser(userInput User, opts ...CreateQueryOption) (Use
return user, err
}

// SendMail sends a message.
//
// See https://docs.microsoft.com/en-us/graph/api/user-sendmail
func (g *GraphClient) SendMail(userID string, message Message, saveToSentItems bool) error {
if g == nil {
return ErrNotGraphClientSourced
}

bodyBytes, err := json.Marshal(struct {
Message Message `json:"message,omitempty"`
SaveToSentItems bool `json:"saveToSentItems,omitempty"`
}{
message,
saveToSentItems,
})
if err != nil {
return fmt.Errorf("could not marshal message body: %w", err)
}

reader := bytes.NewReader(bodyBytes)

resource := fmt.Sprintf("/users/%v/sendMail", userID)

return g.makePOSTAPICall(resource, compileCreateQueryOptions(nil), reader, nil)
}

// UnmarshalJSON implements the json unmarshal to be used by the json-library.
// This method additionally to loading the TenantID, ApplicationID and ClientSecret
// immediately gets a Token from msgraph (hence initialize this GraphAPI instance)
Expand Down
9 changes: 9 additions & 0 deletions Importance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

type MessageImportance string

var (
MessageImportanceLow MessageImportance = "low"
MessageImportanceNormal MessageImportance = "normal"
MessageImportanceHigh MessageImportance = "high"
)
9 changes: 9 additions & 0 deletions InternetMessageHeader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// InternetMessageHeader is a key-value pair that represents an Internet message header that provides details of the network path taken from the message to the recipient. See RFC5322 for the definition.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/InternetMessageHeader
type InternetMessageHeader struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
9 changes: 9 additions & 0 deletions ItemBody.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// ItemBody represents the body of an item, either a message, event, or group post.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/ItemBody
type ItemBody struct {
Content string `json:"content,omitempty"`
ContentType string `json:"contentType,omitempty"`
}
46 changes: 46 additions & 0 deletions Message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package msgraph

import (
"time"
)

// Message represents a single email message.
//
// See https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/Message
type Message struct {
BCCRecipients []Recipient `json:"bccRecipients,omitempty"`
Body *ItemBody `json:"body,omitempty"`
BodyPreview string `json:"bodyPreview,omitempty"`
Categories []string `json:"categories,omitempty"`
CCRecipients []Recipient `json:"ccRecipients,omitempty"`
ChangeKey string `json:"changeKey,omitempty"`
ConversationID string `json:"conversationId,omitempty"`
ConversationIndex string `json:"conversationIndex,omitempty"`
CreatedDateTime time.Time `json:"createdDateTime,omitempty"`
Flag *FollowupFlag `json:"flag,omitempty"`
From *Recipient `json:"from,omitempty"`
HasAttachments *bool `json:"hasAttachments,omitempty"`
ID string `json:"id,omitempty"`
Importance MessageImportance `json:"importance,omitempty"`
InferenceClassification MessageClassification `json:"inferenceClassification,omitempty"`
InternetMessageHeaders []InternetMessageHeader `json:"internetMessageHeaders,omitempty"`
InternetMessageID string `json:"internetMessageId,omitempty"`
IsDeliveryReceiptRequested *bool `json:"isDeliveryReceiptRequested,omitempty"`
IsDraft *bool `json:"isDraft,omitempty"`
IsRead *bool `json:"isRead,omitempty"`
IsReadReceiptRequested *bool `json:"isReadReceiptRequested,omitempty"`
LastModifiedDateTime time.Time `json:"lastModifiedDateTime,omitempty"`
ParentFolderId string `json:"parentFolderId,omitempty"`
ReceivedDateTime time.Time `json:"receivedDateTime,omitempty"`
ReplyTo []Recipient `json:"replyTo,omitempty"`
Sender *Recipient `json:"sender,omitempty"`
SentDateTime time.Time `json:"sentDateTime,omitempty"`
Subject string `json:"subject,omitempty"`
ToRecipients []Recipient `json:"toRecipients,omitempty"`
UniqueBody *ItemBody `json:"uniqueBody,omitempty"`
WebLink string `json:"webLink,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Extensions []Extension `json:"extensions,omitempty"`
MultiValueExtendedProperties []MultiValueLegacyExtendedProperty `json:"multiValueExtendedProperties,omitempty"`
SingleValueExtendedProperties []SingleValueLegacyExtendedProperty `json:"singleValueExtendedProperties,omitempty"`
}
9 changes: 9 additions & 0 deletions MessageClassification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// MessageClassification is the importance of a user's message either inferred or overridden.
type MessageClassification string

var (
MessageClassificationFocused MessageClassification = "focused"
MessageClassificationOther MessageClassification = "other"
)
9 changes: 9 additions & 0 deletions MessageReply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// Structure to reply to messages.
//
// See https://docs.microsoft.com/en-us/graph/api/message-reply
type MessageReply struct {
Comment string `json:"comment,omitempty"` // A comment to add.
Message Message `json:"message,omitempty"` // Properties to be updated when repling.
}
7 changes: 7 additions & 0 deletions MultiValueLegacyExtendedProperty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package msgraph

// MultiValueLegacyExtendedProperty is an extended value that contains a slice of values.
type MultiValueLegacyExtendedProperty struct {
ID string `json:"id,omitempty"`
Value []string `json:"value,omitempty"`
}
8 changes: 8 additions & 0 deletions Recipient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package msgraph

// Represents a user that has sent or been sent an event, message, or group post.
//
// See https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/Recipient
type Recipient struct {
EmailAddress `json:"emailAddress,omitempty"`
}
9 changes: 9 additions & 0 deletions SingleValueLegacyExtendedProperty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package msgraph

// SingleValueLegacyExtendedProperty is an extended that contains a single value.
//
// See https://docs.microsoft.com/en-us/graph/api/resources/SingleValueLegacyExtendedProperty
type SingleValueLegacyExtendedProperty struct {
ID string `json:"id,omitempty"`
Value string `json:"value,omitempty"`
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/open-networks/go-msgraph
module github.com/mypricehealth/go-msgraph

go 1.16

0 comments on commit 045365b

Please sign in to comment.