use of com.microsoft.graph.extensions.Message in project android-java-snippets-sample by microsoftgraph.
the class MessageSnippets method getMessageSnippets.
static MessageSnippets[] getMessageSnippets() {
return new MessageSnippets[] { // Marker element
new MessageSnippets(null) {
@Override
public void request(ICallback callback) {
// Not implemented
}
}, /* Get messages from mailbox for signed in user
* HTTP GET https://graph.microsoft.com/{version}/me/messages
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list_messages
*/
new MessageSnippets<JsonObject>(get_user_messages) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient.getMe().getMessages().buildRequest().get(new ICallback<IMessageCollectionPage>() {
@Override
public void success(IMessageCollectionPage iMessageCollectionPage) {
callback.success(iMessageCollectionPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* Sends an email message on behalf of the signed in user
* HTTP POST https://graph.microsoft.com/{version}/me/messages/sendMail
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_messages
*/
new MessageSnippets<JsonObject>(send_an_email_message) {
@Override
public void request(final ICallback<JsonObject> callback) {
Message message = createMessageObject();
mGraphServiceClient.getMe().getSendMail(message, true).buildRequest().post(new ICallback<Void>() {
@Override
public void success(Void aVoid) {
callback.success(null);
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
} };
}
use of com.microsoft.graph.extensions.Message in project android-java-snippets-sample by microsoftgraph.
the class MessageSnippets method createMessageObject.
private static Message createMessageObject() {
// Get a context so we can interrogate Resources & SharedPreferences
SnippetApp app = SnippetApp.getApp();
SharedPreferences prefs = SharedPrefsUtil.getSharedPreferences();
Message message = new Message();
Recipient recipient = new Recipient();
recipient.emailAddress = new EmailAddress();
recipient.emailAddress.address = prefs.getString(SharedPrefsUtil.PREF_USER_ID, "");
message.toRecipients = Collections.singletonList(recipient);
message.subject = app.getString(R.string.mail_subject);
ItemBody itemBody = new ItemBody();
itemBody.contentType = BodyType.text;
itemBody.content = app.getString(R.string.mail_body);
message.body = itemBody;
return message;
}
Aggregations