How to prevent attachment of all excel in mail servicenow

A very specific question!

To prevent attachments of all Excel files in ServiceNow Mail, you can use a combination of configuration and scripting. Here's a step-by-step guide:

Configuration:

  1. Go to System Properties > Email > Email Server.
  2. Click on the Advanced tab.
  3. In the Attachment filtering section, click on the Edit button next to Attachment types to block.
  4. Add the following MIME types to the list:
    • application/vnd.ms-excel (for Excel 97-2003)
    • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (for Excel 2007 and later)
  5. Click Save.

This configuration will block all Excel files from being attached to emails sent from ServiceNow Mail.

Scripting:

If you want to take it a step further and prevent attachments of specific Excel files based on their content, you can use a script. Here's an example:

  1. Go to Scripting > Scripts > New.
  2. Choose Email as the script type.
  3. Name the script (e.g., "Block Excel Attachments").
  4. In the script, add the following code:
    
    import com.snc.email.api.EmailAttachment;
    import com.snc.email.api.EmailMessage;

// Define the MIME types for Excel files String excelMimeType1 = "application/vnd.ms-excel"; String excelMimeType2 = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

// Define the script emailMessage = new EmailMessage(); emailMessage.setSubject("Test Email");

// Check if the email has any attachments if (emailMessage.getAttachments().size() > 0) { for (EmailAttachment attachment : emailMessage.getAttachments()) { // Check if the attachment is an Excel file if (attachment.getMimeType().equals(excelMimeType1) || attachment.getMimeType().equals(excelMimeType2)) { // Prevent the attachment from being sent attachment.setSent(false); } } }

// Send the email emailMessage.send();


5. Save the script and activate it.

This script will check if the email has any attachments, and if they are Excel files, it will prevent them from being sent.

By combining these configuration and scripting steps, you should be able to prevent attachments of all Excel files in ServiceNow Mail.