Обучение
Пътека за обучение
Use advance techniques in canvas apps to perform custom updates and optimization - Training
Use advance techniques in canvas apps to perform custom updates and optimization
Този браузър вече не се поддържа.
Надстройте до Microsoft Edge, за да се възползвате от най-новите функции, актуализации на защитата и техническа поддръжка.
With the number of unsolicited emails on the rise, security is at the forefront of add-in usage. Currently, partner spam-reporting add-ins are added to the Outlook ribbon, but they usually appear towards the end of the ribbon or in the overflow menu. This makes it harder for users to locate the add-in to report unsolicited emails. In addition to configuring how messages are processed when they're reported, developers also need to complete additional tasks to show processing dialogs or supplemental information to the user.
The integrated spam-reporting feature eases the task of developing individual add-in components from scratch. More importantly, it displays your add-in in a prominent spot on the Outlook ribbon, making it easier for users to locate it and report spam messages. Implement this feature in your add-in to:
Бележка
Integrated spam reporting was introduced in Mailbox requirement set 1.14. For information on client support for this feature, see Supported clients.
The following table identifies which Outlook clients support the integrated spam-reporting feature.
Client | Status |
---|---|
Outlook on the web | Supported* |
new Outlook on Windows | Supported* |
classic Outlook on Windows Version 2404 (Build 17530.15000) |
Supported |
Outlook on Mac Version 16.81 (23121700) or later |
Preview (see Preview the integrated spam-reporting feature in Outlook on Mac) |
Outlook on Android | Not available |
Outlook on iOS | Not available |
Бележка
* In Outlook on the web and the new Outlook on Windows, the integrated spam-reporting feature isn't supported for Microsoft 365 consumer accounts.
To preview the integrated spam-reporting feature in Outlook on Mac, you must install Version 16.81.1217.0 or later. Then, join the Microsoft 365 Insider program and select the Beta Channel option to access Office beta builds.
Съвет
To immediately try out a completed spam-reporting add-in solution, see the Report spam or phishing emails in Outlook sample.
Complete the Outlook quick start, which creates an add-in project with the Yeoman generator for Office Add-ins.
To implement the integrated spam-reporting feature in your add-in, you must configure the following in your manifest.
The runtime used by the add-in. In classic Outlook on Windows, a spam-reporting add-in runs in a JavaScript-only runtime. In Outlook on the web and on Mac and in the new Outlook on Windows, a spam-reporting add-in runs in a browser runtime. For more information, see Runtimes in Office Add-ins.
The button of the spam-reporting add-in that always appears in a prominent spot on the Outlook ribbon. The following is an example of how the button of a spam-reporting add-in appears on the ribbon of the classic Outlook client on Windows. The ribbon UI may vary depending on the platform the user's Outlook client is running on.
The preprocessing dialog. When a user selects the add-in button, a dialog appears with Report and Don't Report options. In this dialog, you can share information about the reporting process or implement input options to get information about a reported message. Input options include checkboxes, radio buttons (preview), and a text box. When a user selects Report from the dialog, the SpamReporting event is activated and is then handled by the JavaScript event handler. The following is an example of a preprocessing dialog in Outlook on Windows. Note that the appearance of the dialog may vary depending on the platform the user's Outlook client is running on.
Select the tab for the type of manifest you're using.
Бележка
Implementing integrated spam reporting with the unified manifest for Microsoft 365 is in public developer preview. It's currently only available to use in classic Outlook on Windows. This shouldn't be used in production add-ins. We invite you to try it out in test or development environments. For more information, see the Public developer preview app manifest schema.
Features in preview, such as the "Don't show me this message again" dialog option and the option to open a task pane from the event.completed
method, aren't currently supported in a spam-reporting add-in with a unified manifest for Microsoft 365. To test these features, use the add-in only manifest.
In your preferred code editor, open the add-in project you created.
Open the manifest.json file.
Add the following object to the "extensions.runtimes" array. Note the following about this markup.
SpamReporting
event occurs and shuts down when the event handler completes.{
"requirements": {
"capabilities": [
{
"name": "Mailbox",
"minVersion": "1.14"
}
]
},
"id": "spam_reporting_runtime",
"type": "general",
"code": {
"page": "https://localhost:3000/commands.html",
"script": "https://localhost:3000/spamreporting.js"
},
"lifetime": "short",
"actions": [
{
"id": "onSpamReport",
"type": "executeFunction"
}
]
},
Add the following object to the "extensions.ribbons" array. Note the following about this markup.
{
"contexts": [
"spamReportingOverride"
],
"tabs": [],
"fixedControls": [
{
"id": "spamReportingButton",
"type": "button",
"label": "Report Spam Message",
"enabled": false,
"icons": [
{
"size": 16,
"url": "https://localhost:3000/assets/icon-16.png"
},
{
"size": 32,
"url": "https://localhost:3000/assets/icon-32.png"
},
{
"size": 80,
"url": "https://localhost:3000/assets/icon-80.png"
}
],
"supertip": {
"title": "Report Spam Message",
"description": "Report an unsolicited message."
},
"actionId": "onSpamReport"
}
],
"spamPreProcessingDialog": {
"title": "Report Spam Message",
"description": "Thank you for reporting this message.",
"spamReportingOptions": {
"title": "Why are you reporting this email?",
"options": [
"Received spam email.",
"Received a phishing email.",
"I'm not sure this is a legitimate email."
]
},
"spamFreeTextSectionTitle": "Provide additional information, if any:",
"spamMoreInfo": {
"text": "Reporting unsolicited messages",
"url": "https://www.contoso.com/spamreporting"
}
}
},
Save your changes.
Съвет
To learn more about manifests for Outlook add-ins, see Office Add-ins manifest.
When your add-in is used to report a message, it generates a SpamReporting
event, which is then processed by the event handler in the JavaScript file of your add-in. To map the name of the event handler you specified in your manifest to its JavaScript counterpart, you must call Office.actions.associate in your code.
In your add-in project, navigate to the ./src directory. Then, create a new folder named spamreporting.
In the ./src/spamreporting folder, create a new file named spamreporting.js.
Open the newly created spamreporting.js file and add the following JavaScript code.
// Handles the SpamReporting event to process a reported message.
function onSpamReport(event) {
// TODO - Send a copy of the reported message.
// TODO - Get the user's responses.
// TODO - Signal that the spam-reporting event has completed processing.
}
// IMPORTANT: To ensure your add-in is supported in Outlook, remember to map the event handler name specified in the manifest to its JavaScript counterpart.
Office.actions.associate("onSpamReport", onSpamReport);
Save your changes.
Your event handler is responsible for processing the reported message. You can configure it to forward information, such as a copy of the message or the options selected by the user in the preprocessing dialog, to an internal system for further investigation.
To efficiently send a copy of the reported message, call the getAsFileAsync method in your event handler. This gets the Base64-encoded EML format of a message, which you can then forward to your internal system.
If you need to keep track of the user's responses to the options and text box in the preprocessing dialog, extract the options
and freeText
values from the SpamReporting
event object. For more information about these properties, see Office.SpamReportingEventArgs.
The following is an example of a spam-reporting event handler that calls the getAsFileAsync
method and gets the user's responses from the SpamReporting
event object.
In the spamreporting.js file, replace its contents with the following code.
// Handles the SpamReporting event to process a reported message.
function onSpamReport(event) {
// Get the Base64-encoded EML format of a reported message.
Office.context.mailbox.item.getAsFileAsync({ asyncContext: event }, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log(`Error encountered during message processing: ${asyncResult.error.message}`);
return;
}
// Get the user's responses to the options and text box in the preprocessing dialog.
const spamReportingEvent = asyncResult.asyncContext;
const reportedOptions = spamReportingEvent.options;
const additionalInfo = spamReportingEvent.freeText;
// Run additional processing operations here.
// TODO - Signal that the spam-reporting event has completed processing.
});
}
// IMPORTANT: To ensure your add-in is supported in Outlook, remember to map the event handler name specified in the manifest to its JavaScript counterpart.
Office.actions.associate("onSpamReport", onSpamReport);
Save your changes.
Бележка
To configure single sign-on (SSO) or cross-origin resource sharing (CORS) in your spam-reporting add-in, you must add your add-in and its JavaScript file to a well-known URI. For guidance on how to configure this resource, see Use single sign-on (SSO) or cross-origin resource sharing (CORS) in your event-based or spam-reporting Outlook add-in.
Once the event handler has completed processing the message, it must call the event.completed method. In addition to signaling to the add-in that the spam-reporting event has been processed, event.completed
can also be used to do the following:
For a list of properties you can include in a JSON object to pass as a parameter to the event.completed
method, see Office.SpamReportingEventCompletedOptions.
Бележка
Code added after the event.completed
call isn't guaranteed to run.
In the spamreporting.js file, replace its contents with the following code.
// Handles the SpamReporting event to process a reported message.
function onSpamReport(event) {
// Get the Base64-encoded EML format of a reported message.
Office.context.mailbox.item.getAsFileAsync({ asyncContext: event }, (asyncResult) => {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
console.log(`Error encountered during message processing: ${asyncResult.error.message}`);
return;
}
// Get the user's responses to the options and text box in the preprocessing dialog.
const spamReportingEvent = asyncResult.asyncContext;
const reportedOptions = spamReportingEvent.options;
const additionalInfo = spamReportingEvent.freeText;
// Run additional processing operations here.
/**
* Signals that the spam-reporting event has completed processing.
* It then moves the reported message to the Junk Email folder of the mailbox, then
* shows a post-processing dialog to the user. If an error occurs while the message
* is being processed, the `onErrorDeleteItem` property determines whether the message
* will be deleted.
*/
const event = asyncResult.asyncContext;
event.completed({
onErrorDeleteItem: true,
moveItemTo: Office.MailboxEnums.MoveSpamItemTo.JunkFolder,
showPostProcessingDialog: {
title: "Contoso Spam Reporting",
description: "Thank you for reporting this message.",
},
});
});
}
// IMPORTANT: To ensure your add-in is supported in Outlook, remember to map the event handler name specified in the manifest to its JavaScript counterpart
Office.actions.associate("onSpamReport", onSpamReport);
Бележка
If you're on classic Outlook on Windows Version 2308 (Build 16724.10000) or later, Outlook on Mac, Outlook on the web, or the new Outlook on Windows, you must use the moveItemTo
property in the event.completed
call to specify the folder to which a reported message is moved once it's processed by your add-in. On earlier Outlook builds on Windows that support the integrated spam-reporting feature, you must use the postProcessingAction
property.
Save your changes.
The following is a sample post-processing dialog shown to the user once the add-in completes processing a reported message in Outlook on Windows. Note that the appearance of the dialog may vary depending on the platform the user's Outlook client is running on.
Съвет
As you develop a spam-reporting add-in that will run in Outlook on Windows, keep the following in mind.
Office.onReady()
and Office.initialize
functions won't run. You must add any add-in startup logic, such as checking the user's Outlook version, to your event handlers instead.In the ./src/commands folder, open commands.html.
Immediately before the closing head tag (</head>
), add the following script entry.
<script type="text/javascript" src="../spamreporting/spamreporting.js"></script>
Бележка
The integrated spam-reporting feature is currently in preview in Outlook on Mac. If you're testing the feature in this client, you must include a reference to the preview version of the Office JavaScript API in your commands.html file.
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/beta/hosted/office.js"></script>
<script type="text/javascript" src="../spamreporting/spamreporting.js"></script>
Save your changes.
From the root directory of your add-in project, open the webpack.config.js file.
Locate the plugins
array within the config
object and add this new object to the beginning of the array.
new CopyWebpackPlugin({
patterns: [
{
from: "./src/spamreporting/spamreporting.js",
to: "spamreporting.js",
},
],
}),
Save your changes.
Бележка
The "Don't show me this message again" option is currently in preview in Outlook on the web and on Windows (new and classic). To preview this feature in classic Outlook on Windows, install Version 2411 (Build 18227.20034) or later. Then, join the Microsoft 365 Insider program and select the Beta Channel option.
Depending on your scenario, you might not need a user to provide additional information about a message they're reporting. If the preprocessing dialog of your spam-reporting add-in only provides information to the user, you can choose to include a "Don't show me this message again" option in the dialog.
To implement this in your add-in, you must specify the NeverShowAgainOption element in your manifest and set it to true
. The following code is an example.
...
<PreProcessingDialog>
<Title resid="PreProcessingDialog.Label"/>
<Description resid="PreProcessingDialog.Text"/>
<NeverShowAgainOption>true</NeverShowAgainOption>
<MoreInfo>
<MoreInfoText resid="MoreInfo.Label"/>
<MoreInfoUrl resid="MoreInfo.Url"/>
</MoreInfo>
</PreProcessingDialog>
...
Note the following behaviors when implementing this option in your add-in.
The "Don't show me this message again" option appears in the preprocessing dialog only if there are no user input options configured, such as reporting options or a text box. If your manifest also specifies user input options, they'll be shown in the dialog instead.
The option to suppress the preprocessing dialog is applied on a per-machine and per-platform basis.
After suppressing the preprocessing dialog, if a user reports a message and has the Reading Pane turned on, a progress notification is shown on the message while it's being processed. If the Reading Pane is turned off, no progress notification is shown.
Бележка
If you implement the "Don't show me this message again" option without configuring a post-processing dialog, a dialog with the following generic message is shown to the user after processing: "Thank you for reporting this message." It's good practice to configure a post-processing dialog to appear after a reported message is processed.
To reenable the preprocessing dialog in classic Outlook on Windows after selecting the "Don't show me this message again" option, perform the following steps.
The preprocessing dialog will appear the next time a message is reported.
Бележка
The option to implement a task pane from the event.completed
method is currently in preview in Outlook on the web and on Windows (new and classic). To preview this feature in classic Outlook on Windows, install Version 2411 (Build 18227.20034) or later. Then, join the Microsoft 365 Insider program and select the Beta Channel option.
Instead of a post-processing dialog, you can implement a task pane to open after a user reports a message. For example, you can use the task pane to show additional information based on the user's input in the preprocessing dialog. Similar to the post-processing dialog, the task pane is implemented through the add-in's event.completed
call.
Бележка
If both the post-processing dialog and task pane capabilities are configured in the event.completed
call, the task pane is shown instead of the dialog.
To configure a task pane to open after a message is reported, you must specify the ID of the task pane in the commandId option of the event.completed
call. The ID must match the value specified in the id
attribute of the Control element that represents the task pane in the manifest.
If you need to pass information to the task pane, specify any JSON data in the contextData option of the event.completed
call. To retrieve the value of the contextData
option, you must call Office.context.mailbox.item.getInitializationContextAsync in the JavaScript implementation of your task pane.
Важно
To ensure that the task pane of the spam-reporting add-in opens and receives context data after a message is reported, you must set the moveItemTo
option of the event.completed
call to Office.MailboxEnums.MoveSpamItemTo.NoMove
.
The following code is an example.
...
event.completed({
commandId: "msgReadOpenPaneButton",
contextData: JSON.stringify({ a: "aValue", b: "bValue" }),
moveItemTo: Office.MailboxEnums.MoveSpamItemTo.NoMove
});
If another task pane is open or pinned at the time a message is reported, the open task pane is closed then the task pane of the spam-reporting add-in is shown.
As you develop and test the integrated spam-reporting feature in your add-in, be mindful of its characteristics and limitations.
In Outlook on the web and on Windows (new and classic), an integrated spam-reporting add-in replaces the native Report button in the Outlook ribbon. If multiple spam-reporting add-ins are installed, they will all appear in the Report section of the ribbon.
A spam-reporting add-in can run for a maximum of five minutes once it's activated. Any processing that occurs beyond five minutes will cause the add-in to time out. If the add-in times out, a dialog will be shown to the user to notify them of this.
In classic Outlook on Windows, a spam-reporting add-in can be used to report a message even if the Reading Pane of the Outlook client is turned off. In Outlook on the web, on Mac, and in new Outlook on Windows, the spam-reporting add-in can be used if the Reading Pane is turned on or the message to be reported is open in another window.
Only one message can be reported at a time. If you select multiple messages to report, the button of the spam-reporting add-in becomes unavailable.
In classic Outlook on Windows, only one reported message can be processed at a time. If a user attempts to report another message while the previous one is still being processed, a dialog will be shown to notify them of this.
This doesn't apply to Outlook on the web or on Mac, or to the new Outlook on Windows. In these Outlook clients, a user can report a message from the Reading Pane and can simultaneously report each message that's open in a separate window.
The add-in can still process the reported message even if the user navigates away from the selected message. In Outlook on Mac, this is only supported if a user reports a message while it's open in a separate window. If the user reports a message while viewing it from the Reading Pane and then navigates away from it, the reporting process is terminated.
In Outlook on the web and the new Outlook on Windows, if a message is reported while it's open in a separate window, a post-processing dialog isn't shown to the user.
The buttons that appear in the preprocessing and post-processing dialogs aren't customizable. Additionally, the text and buttons in the timeout and ongoing report dialogs can't be modified.
The integrated spam-reporting and event-based activation features must use the same runtime. Multiple runtimes aren't currently supported in Outlook. To learn more about runtimes, see Runtimes in Office Add-ins.
A spam-reporting add-in only implements function commands. A task pane command can't be assigned to the spam-reporting button on the ribbon. If you want to implement a task pane in your add-in, you must configure it in your manifest as follows:
xsi:type
attribute to ShowTaskpane
.Note that a separate button to activate the task pane will be added to the ribbon, but it won't appear in the dedicated spam-reporting area of the ribbon.
As you develop your spam-reporting add-in, you might need to troubleshoot issues, such as your add-in not loading. For guidance on how to troubleshoot a spam-reporting add-in, see Troubleshoot event-based and spam-reporting add-ins.
Обратна връзка за Office Add-ins
Office Add-ins е проект с отворен код. Изберете връзка, за да предоставите обратна връзка:
Обучение
Пътека за обучение
Use advance techniques in canvas apps to perform custom updates and optimization - Training
Use advance techniques in canvas apps to perform custom updates and optimization