Share via

Microsoft Email Specification ADD-IN

Aubrey Xaba 0 Reputation points
2023-08-16T14:19:03.7933333+00:00

Good day I trust you well,

Thank you in advance for assistance,

Please see below JavaScript code trying to create a Microsoft Outlook Add-In for Email Specification,

<script>
    Office.onReady((info) => {
        if (info.host === Office.HostType.Outlook) {
            document.getElementById("ClassifyButton").onclick = ClassifyEmail;
        }
    });

    function ClassifyEmail() {
        var classification = document.getElementById("classification").value;
        if (!classification) {
            alert("Please select a classification before sending.");
        } else {
            Office.context.mailbox.item.subject.setAsync(
                "[" + classification + "]",
                function (asyncResult) {
                    if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
                        // Send the email after setting the classification
                        Office.context.mailbox.item.saveAsync(function (asyncResult) {
                            if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
                                Office.context.mailbox.item.send();
                            } else {
                                console.error(asyncResult.error.message);
                            }
                        });
                    } else {
                        console.error(asyncResult.error.message);
                    }
                }
            );
        }
    }
</script>

I tried so many ways to prevent an email to be sent before specified, please assist as I have tried a couple of ways without luck, please see below manifest code for your efference,  

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"   xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp"> 	<Id>1e7e38da-7ad6-429a-9c6f-81aa1b9c9344</Id> 	<Version>1.0.0.0</Version> 	<ProviderName>Contoso</ProviderName> 	<DefaultLocale>en-US</DefaultLocale> 	<DisplayName DefaultValue="Email Classification"/> 	<Description DefaultValue="NMI Email Classification Add-In."/> 	<IconUrl DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 	<HighResolutionIconUrl DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 	<SupportUrl DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 	<AppDomains> 		<AppDomain>https://www.contoso.com</AppDomain> 	</AppDomains> 	<Hosts> 		<Host Name="Mailbox"/> 	</Hosts> 	<Requirements> 		<Sets> 			<Set Name="Mailbox" MinVersion="1.1"/> 		</Sets> 	</Requirements> 	<FormSettings> 		<Form xsi:type="ItemRead"> 			<DesktopSettings> 				<SourceLocation DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Add-In-LocalhostRead/Home/EmailClassification.html"/> 				<RequestedHeight>250</RequestedHeight> 			</DesktopSettings> 		</Form> 	</FormSettings> 	<Permissions>ReadWriteItem</Permissions> 	<Rule xsi:type="RuleCollection" Mode="Or"> 		<Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Edit"/> 		<Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit"/> 	</Rule> 	<DisableEntityHighlighting>false</DisableEntityHighlighting> 	<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0"> 		<Requirements> 			<bt:Sets DefaultMinVersion="1.3"> 				<bt:Set Name="Mailbox"/> 			</bt:Sets> 		</Requirements> 		<Hosts> 			<Host xsi:type="MailHost"> 				<DesktopFormFactor>  					<!-- Message Compose --> 					<ExtensionPoint xsi:type="MessageComposeCommandSurface"> 						<OfficeTab id="TabDefault"> 							<Group id="msgComposeCmdGroup"> 								<Label resid="CommandsGroup.Label"/> 								<Control xsi:type="Button" id="msgSendClassify"> 									<Label resid="TaskpaneButton.Label"/> 									<Supertip> 										<Title resid="TaskpaneButton.SupertipTitle"/> 										<Description resid="TaskpaneButton.SupertipText"/> 									</Supertip> 									<Icon> 										<bt:Image size="16" resid="Icon.16x16"/> 										<bt:Image size="32" resid="Icon.32x32"/> 										<bt:Image size="80" resid="Icon.80x80"/> 									</Icon> 									<Action xsi:type="ShowTaskpane"> 										<SourceLocation resid="EmailClassification.Url"/> 									</Action> 								</Control> 							</Group> 						</OfficeTab> 					</ExtensionPoint> 				</DesktopFormFactor> 			</Host> 		</Hosts> 		<Resources> 			<bt:Images> 				<bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 				<bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 				<bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Content/Icons/NMI_logo_black2.png"/> 			</bt:Images> 			<bt:Urls> 				<bt:Url id="EmailClassification.Url" DefaultValue="https://localhost:3000/NMI.Office.AddIn.ClassificationWeb/Add-In-LocalhostRead/Home/EmailClassification.html"/> 			</bt:Urls> 			<bt:ShortStrings> 				<bt:String id="CommandsGroup.Label" DefaultValue="Contoso Add-in"/> 				<bt:String id="TaskpaneButton.Label" DefaultValue="Email Classification"/> 				<bt:String id="TaskpaneButton.SupertipTitle" DefaultValue="Email Classification"/> 			</bt:ShortStrings> 			<bt:LongStrings> 				<bt:String id="TaskpaneButton.SupertipText" DefaultValue="Open Email Classification Add-In"/> 			</bt:LongStrings> 		</Resources> 	</VersionOverrides> </OfficeApp>

The code works but I can not get it to prevent the user to specify email before sending an email

Thank you 
Microsoft 365 and Office | Development | Office JavaScript API
Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.