Get Email body and set it as To Do Task content

This commit is contained in:
luismanez 2020-09-28 14:51:38 +02:00
parent e43f35704a
commit 0fbe0d1edc
3 changed files with 12 additions and 9 deletions

View File

@ -20,12 +20,17 @@ export interface ICreateTaskWebPartProps {
export default class CreateTaskWebPart extends BaseClientSideWebPart<ICreateTaskWebPartProps> {
private _graphHttpClient: MSGraphClient;
private _mailBody: string;
protected onInit(): Promise<void> {
return new Promise((resolve, reject) => {
this.context.msGraphClientFactory.getClient().then(client => {
this._graphHttpClient = client;
const mailboxItem: Office.MessageRead = this.context.sdks.office.context.mailbox.item;
mailboxItem.body.getAsync(Office.CoercionType.Text, (asyncResult: Office.AsyncResult<string>) => {
this._mailBody = asyncResult.value;
resolve();
});
}).catch(error => {
console.log(error);
reject(error);
@ -43,7 +48,8 @@ export default class CreateTaskWebPart extends BaseClientSideWebPart<ICreateTask
id: mailboxItem.itemId,
subject: mailboxItem.subject,
from: mailboxItem.from.emailAddress,
to: mailboxItem.to[0].emailAddress
to: mailboxItem.to[0].emailAddress,
body: this._mailBody
}
};
return context;

View File

@ -17,8 +17,6 @@ import {
MessageBarType
} from "office-ui-fabric-react";
import { MSGraphClient } from "@microsoft/sp-http";
export default class CreateTask extends React.Component<
ICreateTaskProps,
ICreateTaskState
@ -30,9 +28,7 @@ export default class CreateTask extends React.Component<
listItemAdded: false,
selectedList: undefined,
todoLists: [],
newTaskTitle: this.props.context.item
? this.props.context.item.subject
: "New Task title here!",
newTaskTitle: this.props.context.item ? this.props.context.item.subject : "New Task title here!",
showSelectListError: false
};
@ -166,7 +162,7 @@ export default class CreateTask extends React.Component<
status: "notStarted",
title: taskTitle,
body: {
content: "You have a new task to do added from SPFx component!",
content: this.props.context.item.body,
contentType: "text",
},
};

View File

@ -3,4 +3,5 @@ export interface IMailItem {
subject: string;
from: string;
to: string;
body: string;
}