Class Message
- All Implemented Interfaces:
ICreatable,IUpdatable
- Direct Known Subclasses:
EventMessage
The Message resource represents an email message in Microsoft 365. Messages can be drafts or sent items, and can include attachments, recipients, and various metadata. This class provides comprehensive access to all message properties and supports operations like create, read, update, delete, send, forward, and reply.
Common message operations include:
- Creating and sending new messages
- Reading message properties (subject, body, recipients, etc.)
- Managing message attachments (file attachments, item attachments)
- Replying to and forwarding messages
- Moving messages between folders
- Marking messages as read/unread
- Flagging messages for follow-up
- Working with extended properties
Example usage:
GraphClient client = new GraphClient();
// ... configure authentication ...
// Create and send a new message
Message message = new Message();
message.setSubject(\"Hello from Graph API\");
ItemBody body = new ItemBody();
body.setContentType(BodyType.TEXT);
body.setContent(\"This is a test message\");
message.setBody(body);
EmailAddress to = new EmailAddress();
to.setAddress(\"user@example.com\");
message.getToRecipients().add(to);
client.sendMessage(message);
// List messages in inbox
List<Message> messages = client.listMessages();
for (Message msg : messages) {
System.out.println(msg.getSubject());
}
- Since:
- 1.0
- See Also:
- Message resource type, Send message, List messages
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<Attachment>protected List<EmailAddress>protected ItemBodyprotected Stringprotected List<EmailAddress>protected Stringprotected Stringprotected Stringprotected Dateprotected List<ExtendedProperty>protected FollowupFlagprotected EmailAddressprotected booleanprotected Stringprotected Importanceprotected InferenceClassificationprotected List<InternetMessageHeader>protected Stringprotected booleanprotected booleanprotected booleanprotected booleanprotected Dateprotected booleanprotected Stringprotected Dateprotected List<EmailAddress>protected EmailAddressprotected Dateprotected Stringprotected List<EmailAddress>protected ItemBodyprotected Stringprotected booleanprotected String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetBody()getFlag()getFrom()getId()booleanbooleanbooleanisDraft()booleanisRead()booleanbooleanvoidsetAsDeliveryReceiptRequested(boolean isDeliveryReceiptRequested)voidsetAsDraft(boolean isDraft)voidsetAsRead(boolean isRead)voidsetAsReadReceiptRequested(boolean isReadReceiptRequested)voidvoidsetFlag(FollowupFlag flag)voidsetFrom(EmailAddress from)voidsetHasAttachments(boolean hasAttachments)voidvoidsetImportance(Importance importance)voidsetInferenceClassification(InferenceClassification inferenceClassification)voidsetInternetMessageId(String internetMessageId)voidsetSender(EmailAddress sender)voidsetSubject(String subject)voidsetUnsubscribeData(String unsubscribeData)voidsetUnsubscribeEnabled(boolean unsubscribeEnabled)Converts this object to its JSON representation for creation.toString()Converts this object to its JSON representation for update.toUpdateJson(List<String> propertyNames)Converts this object to JSON for update with specific properties.boolean
-
Field Details
-
id
-
changeKey
-
bccRecipients
-
body
-
bodyPreview
-
categories
-
ccRecipients
-
conversationId
-
conversationIndex
-
createdTime
-
flag
-
from
-
hasAttachments
protected boolean hasAttachments -
importance
-
inferenceClassification
-
internetMessageHeaders
-
internetMessageId
-
isDeliveryReceiptRequested
protected boolean isDeliveryReceiptRequested -
isDraft
protected boolean isDraft -
isRead
protected boolean isRead -
isReadReceiptRequested
protected boolean isReadReceiptRequested -
lastModifiedTime
-
mentionsPreview
protected boolean mentionsPreview -
parentFolderId
-
receivedTime
-
replyTo
-
sender
-
sentTime
-
subject
-
toRecipients
-
uniqueBody
-
unsubscribeData
-
unsubscribeEnabled
protected boolean unsubscribeEnabled -
webLink
-
extendedProperties
-
attachments
-
-
Constructor Details
-
Message
public Message() -
Message
-
-
Method Details
-
toAttachmentItem
-
toCreateJson
Description copied from interface:ICreatableConverts this object to its JSON representation for creation.This method generates a JSON string containing all properties needed to create a new instance of this resource in Microsoft Graph. Only properties appropriate for creation should be included (e.g., excluding read-only properties like ID, createdTime, etc.).
- Specified by:
toCreateJsonin interfaceICreatable- Returns:
- JSON string representation for creating this resource
-
toUpdateJson
Description copied from interface:IUpdatableConverts this object to its JSON representation for update.This method generates a JSON string containing all modified properties that should be updated in Microsoft Graph. Only writeable properties with non-null values are typically included.
- Specified by:
toUpdateJsonin interfaceIUpdatable- Returns:
- JSON string representation for updating this resource
-
toUpdateJson
Description copied from interface:IUpdatableConverts this object to JSON for update with specific properties.This method generates a JSON string containing only the specified properties. This enables partial updates where only certain fields need to be modified, reducing payload size and avoiding unintended changes to other properties.
- Specified by:
toUpdateJsonin interfaceIUpdatable- Parameters:
propertyNames- List of property names to include in the JSON. If null or empty, all modified properties are included.- Returns:
- JSON string representation for updating specific properties
-
toString
-
getId
-
setId
-
getChangeKey
-
getBccRecipients
-
getBody
-
setBody
-
getBodyPreview
-
getCategories
-
getCcRecipients
-
getConversationId
-
getConversationIndex
-
getCreatedTime
-
getFlag
-
setFlag
-
getFrom
-
setFrom
-
hasAttachments
public boolean hasAttachments() -
setHasAttachments
public void setHasAttachments(boolean hasAttachments) -
getImportance
-
setImportance
-
getInferenceClassification
-
setInferenceClassification
-
getInternetMessageHeaders
-
getInternetMessageId
-
setInternetMessageId
-
isDeliveryReceiptRequested
public boolean isDeliveryReceiptRequested() -
setAsDeliveryReceiptRequested
public void setAsDeliveryReceiptRequested(boolean isDeliveryReceiptRequested) -
isDraft
public boolean isDraft() -
setAsDraft
public void setAsDraft(boolean isDraft) -
isRead
public boolean isRead() -
setAsRead
public void setAsRead(boolean isRead) -
isReadReceiptRequested
public boolean isReadReceiptRequested() -
setAsReadReceiptRequested
public void setAsReadReceiptRequested(boolean isReadReceiptRequested) -
getLastModifiedTime
-
mentionsPreview
public boolean mentionsPreview() -
getParentFolderId
-
getReceivedTime
-
getReplyTo
-
getSender
-
setSender
-
getSentTime
-
getSubject
-
setSubject
-
getToRecipients
-
getUniqueBody
-
getUnsubscribeData
-
setUnsubscribeData
-
unsubscribeEnabled
public boolean unsubscribeEnabled() -
setUnsubscribeEnabled
public void setUnsubscribeEnabled(boolean unsubscribeEnabled) -
getWebLink
-
getExtendedProperties
-
getAttachments
-