How to forward an email using Office JS Add-in API? - outlook

I'm trying to develop an add-in using Office 365 Javascript API for Outlook. I'm using Microsoft's reference to look for methods that will allow me to forward the currently opened email when I click a button. The issue is that there's not a single method on the reference that can do that, how can I forward an email using Office JS API?
I imagine it should be something like that:
var item = Office.context.mailbox.item; # item represents the currently opened email
item.Forward(email)

There isn't a method for forwarding the current email included in Office.js.
One alternative solution would be to use Microsoft Graph for this. You'll need to register an Application ID using the steps outlined in Authenticate a user with an single-sign-on token in an Outlook add-in.
Once you have a token and the message's id, you call into Microsoft Graph /forward endpoint:
POST https://graph.microsoft.com/v1.0/me/messages/{id}/forward
Content-type: application/json
{
"comment": "",
"toRecipients": [
{
"emailAddress": {
"name": "recipient-name",
"address": "recipient-email"
}
}
]
}

Currently the feature you requested is not part of the product.
However, we track Outlook add-in feature requests on our user-voice page. Please add your request there.
Feature requests on user-voice are considered when we go through our planning process.
[Outlook Add-ins Engineering Team]

Related

How to fetch email internet headers in an on-send add-in?

We have a client that requires that an action take place when sending emails with certain Microsoft Information Protection/Azure Information Protection (MSIP/AIP) labels. We have a desktop Outlook add-in that does this perfectly.
Now however the client is requesting this same add-in but using the new modern style Outlook add-ins. We have created an on-send add-in to accomplish this, but we cannot get access to any internet headers in an Office.ComposeMessage. In fact, we cannot get any headers to be returned.
Here is our code:
async function fetchInternetHeaders(mailItem: Office.MessageCompose,
tags: string[]): Promise<string[]> {
return new Promise(function(resolve, reject) {
try {
let myTags: string[] = [
"msip_labels", // This is the value we need
"x-ms-has-attach", // This is for testing
"PR_SUBJECT_W", // This is for testing
"http://schemas.microsoft.com/mapi/proptag/0x0037001F", // test
"http://schemas.microsoft.com/mapi/proptag/0x5D07001F", // test
"http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/msip_labels/0x0000001F", // Another way to get msip_labels
];
mailItem.internetHeaders.getAsync(myTags, function(asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
debug.Log("onSend.fetchInternetHeaders", "Selected headers: " + JSON.stringify(asyncResult.value));
} else {
debug.Log(
"onSend.fetchInternetHeaders",
"Error getting selected headers: " + JSON.stringify(asyncResult.error)
);
}
resolve(["FetchedInternetHeaders"]);
});
} catch (error) {
debug.Log("onSend.fetchInternetHeaders", "Error occurred", error);
reject(error);
}
});
Note: We ignored the parameter "tags" to make everything as simple as possible.
The call succeeds but the returned array is always empty, even for simple properties like the email Subject. What are we doing wrong?
Both COM add-ins and Web add-ins don't provide any internet headers until the message is sent out. You may expect the internet headers set when the message is put to the Sent Items folder, but before that they are not created and stamped by the service/transport provider.
Most probably you need to access user properties, see the UserProperties object in the Outlook object model. But the Office JavaScript API (OfficeJS) doesn't provide anything for that out of the box, you need to use EWS or Graph API to access such properties from web add-ins.
You can specify data specific to an item in the user's mailbox using the CustomProperties object. For example, your mail add-in could categorize certain messages and note the category using a custom property messageCategory. Or, if your mail add-in creates appointments from meeting suggestions in a message, you can use a custom property to track each of these appointments. This ensures that if the user opens the message again, your mail add-in doesn't offer to create the appointment a second time.
Be aware, changes to custom properties are stored on in-memory copies of the properties for the current Outlook session. To make sure these custom properties will be available in the next session, use CustomProperties.saveAsync.
These add-in-specific, item-specific custom properties can only be accessed by using the CustomProperties object. Like I wrote earlier, these properties are different from the custom, MAPI-based UserProperties in the Outlook object model, and extended properties in Exchange Web Services (EWS). You cannot directly access CustomProperties by using the Outlook object model, EWS, or REST. To learn how to access CustomProperties using EWS or REST, see the section Get custom properties using EWS or REST.
You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team go through the planning process. Use the github label: Type: product feature request at https://aka.ms/M365dev-suggestions .

How to remove add-in using REST API in office add-in for outlook or event handler for when user removes add-in

I have a use case to receive call-back event when user removes add-in from outlook or need to remove add-in using REST API. can any guide ?
OfficeJS doesn't provide any callback or events for that. Feature requests on Tech Community are considered, when the dev team go through the planning process. Use the github label: “Type: product feature request” at https://aka.ms/M365dev-suggestions .

How to send an email from an outlook office add on?

I am trying to build an outlook add on, using react. I looked everywhere trying to find something that uses the mailbox in which the addon has been opened from, to programmatically send an email to a specified user.
Something similar to the google's command:
GmailApp.createDraft(e.parameters.address, e.parameters.subject, e.parameters.body, {
htmlBody: e.parameters.body,
name: 'Automatic Sender'
}).send();
Is the mail-sending process available on outlook?
Outlook web add-ins work under the context of currently selected item only. OfficeJS doesn't provide anything for creating and sending emails programmatically.
In Outlook add-ins you may consider using EWS, see Call web services from an Outlook add-in for more information. Also you may take a look at the Graph API as a possible workaround.

Office-JS Outlook add-in enter forward mode

I am new to Outlook add-in development. I want to automate a simple process; selecting an e-mail and clicking on a button "Forward" inside my add-in which makes the e-mail enter Forward mode (replicating the functionality of the Forward button in Outlook) and adding a recipient that I specify in my code. The desired function should look like this, but of course this is not working:
export async function forwardMail(){
var item = Office.context.mailbox.item; //=the email
item.Forward();
item.addRecipient("my-email-address#outlook.com");
}
And like mentioned, this function should simply enter the Forward mode in the Outlook application and add my recipient.
Office web add-ins are working under the current item in Outlook only:
I want to automate a simple process; selecting an e-mail and clicking on a button "Forward" inside my add-in which makes the e-mail enter Forward mode
You can do the required modifications using OfficeJS or EWS, Outlook REST API or MS Graph API. For example, once you have a token and the message's id, you call into Microsoft Graph /forward endpoint:
POST https://graph.microsoft.com/v1.0/me/messages/{id}/forward
Content-type: application/json
{
"comment": "",
"toRecipients": [
{
"emailAddress": {
"name": "recipient-name",
"address": "recipient-email"
}
}
]
}

Send Attachments to Bot in Teams

I'm working with BotBuilder in .NET C#.
I can't figure out how I can send an attachment to the bot using Teams client - I've tried using the Windows desktop app and the web client but neither shows an attachment button in a chat with the bot.
I also tried with the Android client and found that I could send image attachments but not other file types, which I then went back and found that I could do the same in desktop/web clients by pasting the image into the chat box.
Using this method I do get an item in Activity.Attachments with ContentType="image/*". Any other type of file that I try to attach in the Android client is not sent to the bot (nothing in the Activity.Attachments collection) and as I said the other clients won't allow me to even attach anything in 1:1 chat.
Attaching a file in a Teams Channel adds the file to the Channel but I don't get any reference to the attachment if I #mention the bot along with the attachment.
The only mention of consuming attachments in bot sent via Teams I can find is here where it's stated that you'll need to use a JwtToken to access the file. I'm guessing this is currently a limitation in Teams as I'm able to send/receive attachments from other channels, but I'd like to confirm that there isn't some nuance that I'm missing.
Currently, Microsoft Teams does not support the ability to send non-image files to bots.
We are currently working on delivering this feature, but we do not yet have an ETA.
Image attachment can be send through Teams by copy pasting them in the Chat window.Teams have pushed the new Build where you can have Attachment Functionality available in Chat BOT. Now you can attach any file in the teams channel but you need to continue to send the Jwt token.
You can explore the type FileDownloadInfo which can be used to know the file type, content and other required details after you send the attachment to the BOT.
To answer your first question. Microsoft Teams does not show "attachment" button by default. You can install "App Studio" in Teams, and create an app for your bot, specify your app allows upload attachments. And install it in your own Team account for testing.
The second question, you can't get the image attachment. The JSON from Microsoft Teams channel is different from other channels.
You may notice the "contentType" is different, and the "contentUrl" requires a login in order to download the image. You need to use "content.downloadUrl" instead.
"attachments": [
{
"contentType": "application/vnd.microsoft.teams.file.download.info",
"contentUrl": "https://xxx-xxx.sharepoint.com/personal/xxxx/Documents/Microsoft Teams Chat Files/Cloud section in Singapore.PNG",
"content": {
"downloadUrl": "https://xxxx-xx.sharepoint.com/personal/xxxx/_layouts/15/download.aspx?UniqueId=a3cf2177-1cc7-433b-8344-129140c0694e&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAvc2FnZTM2NS1teS5zaGFyZXBvaW50LmNvbUAzZTMyZGQ3Yy00MWY2LTQ5MmQtYTFhMy1jNThlYjAyY2Y0ZjgiLCJpc3MiOiIwMDAwMDAwMy0wMDAwLTxxxxx&ApiVersion=2.0",
"uniqueId": "xxxx-1cc7-433b-8344-xxxxxx",
"fileType": "png"
},
"name": "Cloud section in Singapore.PNG",
"thumbnailUrl": null
}
]

Resources