Limit No.of recipients while compose an email through email client configuration

Prakash Pareek
Tera Expert

Hi, can we limit the no.of recipients for a particular email client configuration (if a make a new email client configuration and want to limit only 10 recipients can only be given), and also can we limit the max size of an attachment that would be shared through the email (email client configuration) ... If yes then how is it possible, could anyone please guide me through this  

4 REPLIES 4

Harshal Aditya
Mega Sage
Mega Sage

Hi @Prakash Pareek ,

 

Hope you are doing well.

 

For Attachment please refer below link -

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0785037

 

Not sure if we can limit number of recipients- OOB. please let me know if you find any thing such

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

 

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Prakash Pareek ,
I trust you are doing great.
First, create a Business Rule that runs on the Email Configuration [sys_email_client_configuration] table. This rule will trigger whenever a new email client configuration is created. Here's an example of the code you can use in the Business Rule script:

 

(function executeRule(current, previous) {
  // Define the maximum number of recipients allowed
  var maxRecipients = 10;
  
  // Check if the number of recipients exceeds the limit
  if (current.recipients.length > maxRecipients) {
    current.recipients.splice(maxRecipients); // Remove extra recipients
    
    gs.addInfoMessage('The number of recipients has been limited to ' + maxRecipients);
  }
})(current, previous);

 

This code checks the number of recipients specified in the recipients field of the email client configuration record. If the number exceeds the maxRecipients limit, it removes the extra recipients and displays an information message.

Next, to limit the maximum size of an attachment shared through the email, you can modify the Outbound Email action script. This script is associated with the email client configuration and controls the behavior of the email sender. Here's an example of the code you can use:

 

(function runMailScript(source, email, template, email_action, event) {
  // Define the maximum attachment size in bytes
  var maxAttachmentSize = 10 * 1024 * 1024; // 10 MB
  
  // Check if the attachment size exceeds the limit
  if (email.hasAttachment() && email.attachment.getSize() > maxAttachmentSize) {
    email.attachment = null; // Remove the attachment
    
    gs.addErrorMessage('The attachment size exceeds the maximum limit of 10 MB');
  }
})(source, email, template, email_action, event);

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi while I compose the email through the ritm form ... by mail ui action ... I want the no.of recipient to be 10 ... and as per your code it will be set for the email client configuration ... Could you suggest any development on the email which we send ... and make no.of the recipient not greater than 10 ... please refer the attachment ... The 'TO' one ....I want to limit there ... Thank for the reply

PrakashPareek_0-1687782269082.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Prakash Pareek 

I believe you are referring to email client template which opens up a new page

that page is an OOB ui page whose code is not accessible

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader