GraphService
After you register your app and get authentication tokens for a user or service, you can make requests to the Microsoft Graph API.
createOAuthMailClient(String:email, String:clientId, String:secretKey, String:tenantId) → GraphService
Create an instance of the class GraphService to send, read, reply, delete messages.
var graphService = createOAuthMailClient("email", "clientId", "secretKey", "tenantId");
setMailFolder(String:folderName)
Set the default working folder, so you only have to set it once and the following actions will be performed inside the selected folder. If it’s not set, by default is “Inbox“.
This was added in AIQ 4.9.2. See the release notes for Release 4.9.2
graphService.setMailFolder("Junk Items");
var junkMessages = graphService.getAllMessages(); //this will get all the emails in junk folder
graphService.setMailFolder("Deleted Items");
var deletedMessages = graphService.getAllMessages(); //this will get all the emails in delete folder
sendMessage(GraphMessage:gMsg) → Boolean
Send the email.
var msg = graphService.createMailMessage("Email subject", "Email body");
msg.addTo(["appvancetest@appvance.com"]);
var sent = graphService.sendMessage(msg);
replyMessage(String:mainMessageId, String:comment) → Boolean
Reply to a email.
var mainMessage = graphService.getMessage("test@appvance.com", "Email subject");
var comment = "This is a reply message!";
var sent = graphService.replyMessage(mainMessage.id, comment);
if (sent) {
log("Reply sent.");
} else {
throw new Error('An error occurred while sending the email.');
}
replyToAllMessage(String:mainMessageId, String:comment) → Boolean
Reply to a email.
var mainMessage = graphService.getMessage("test@appvance.com", "Email subject");
var comment = "This is a reply all message!";
var sent = graphService.replyToAllMessage(mainMessage.id, comment);
if (sent) {
log("Reply sent.");
} else {
throw new Error('An error occurred while sending the email.');
}
This was added in AIQ 4.9.2. See the release notes for Release 4.9.2
deleteMessage(String:id) → Boolean
Delete a specific email.
var message = graphService.getMessage("id");
graphService.deleteMessage(message.id);
getAllMessages() → List<Message>
Get the all the messages from Inbox folder.
var messageList = graphService.getAllMessages();
var count = messageList.size();
for (var i = 0; i < count; i++) {
log("From: " + messageList.get(i).from.emailAddress.address);
log("Subject: " + messageList.get(i).subject);
log("Body: " + messageList.get(i).body.content);
log("");
}
getCountUnreadMessages() → Interger
Return the count of the unread messages in the Inbox folder.
var unreadCount = graphService.getCountUnreadMessages();
log("Count of unread messages: " + unreadCount);
getCountTotalMessages() → Interger
Return the count of all the messages in the Inbox folder.
var totalCount = graphService.getCountTotalMessages();
log("Count of unread messages: " + totalCount);
getUnreadMessages() → List<Message>
Return the unread messages in the Inbox folder.
var unreadList = graphService.getUnreadMessages();
var unreadCount = unreadList.size();
if (unreadCount > 0) {
for (var i = 0; i < unreadCount; i++) {
log("Id: " + unreadList.get(i).id);
log("From: " + unreadList.get(i).from.emailAddress.address);
log("Subject: " + unreadList.get(i).subject);
log("Body: " + unreadList.get(i).body.content);
log("");
}
} else {
log("There's no unread messages.");
}
getMessage(String:id) → Message
Search a message by ID and return all the details of this.
var message = graphService.getMessage("id");
if(message != null){
log("Id: " + message.id);
log("From: " + message.from.emailAddress.address);
log("Subject: " + message.subject);
log("Body: " + message.body.content);
} else {
log("Email not found.");
}
getMessage(String:from, String:subject) → Message
Search a message by From recipient and subject, then return all the details of this.
var message = graphService.getMessage("email","subject");
if(message != null){
log("Id: " + message.id);
log("From: " + message.from.emailAddress.address);
log("Subject: " + message.subject);
log("Body: " + message.body.content);
} else {
log("Email not found.");
}