January 26th, 2022

Outlook JavaScript API deprecation for contentType property

The AttachmentDetails.contentType property in the Outlook JavaScript Mailbox API gives an add-in developer the ability to get the MIME content type of an Outlook item attachment. However, while the value returned by the contentType property is a direct lookup of the attachment’s extension, the internal mapping isn’t actively maintained or standardized. As such, we’ve deprecated this property and recommend you grab the attachment’s extension and process accordingly. For example, read the ContentType returns unexpected values issue in the GitHub office-js repo.

Code sample: contentType property deprecation

The following sample code gets the attachment’s file extension then handles if it’s an mp4 video file. 

var fileExtension = Office.context.mailbox.item.attachments[0].name.split(".").pop().toLowerCase(); 

if (fileExtension == "mp4") { 
  console.log("This is a video file"); 
}

The contentType property is still available to add-ins that currently use it. However, we advise you to replace the reference as soon as possible. 

New add-ins should avoid using this property at all. 

More resources

Happy coding! 

Topics
Outlook

0 comments

Discussion are closed.