- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 06:18 PM
Hi folks,
I have previous raised a question about inbound action script that prevents excessive attachment from attaching. After attempting to implement the script, I realised ServiceNow seems to stop the email from processing if an attachment is over-sized ( Email.attachment.size >= glide.email.inbound.max_total_attachment_size_bytes : default 16m)
Therefore the script would never seem to be reached if the size condition is met, but following would be a plan to achieve this
1) Change the value of glide.email.inbound.max_total_attachment_size_bytes to 10485760 (100m)
2) Create a new sys_properties of test.email.inbound.max_total_attachment_size_bytes and set value to (16m)
3) Create Inbound Action Script including the code below
If attachment is over 16 mb and less than 100m, it will fires off 'systems_email_oversize.bounce', notifying the sender that the attachments are not attached.
Any advice would be appreciated.
Kind regards,
var max_attach_bytes = gs.getProperty('test.email.inbound.max_total_attachment_size_bytes'); | |||
//total attachments size | |||
var total_size=0; | |||
var att = new GlideAggregate('sys_attachment'); | |||
att.addEncodedQuery('table_sys_id=' + eml.sys_id); | |||
att.addAggregate('SUM', 'size_bytes'); | |||
att.query(); | |||
if (att.next()) | |||
total_size = att.getAggregate('SUM', 'size_bytes'); | |||
// if total size exceeds the maximum limit, fires off the bounce event | |||
if (total_size >= max_attach_bytes) | |||
gs.eventQueue('systems_email_oversize.bounce', null, email.origemail, email.subject); |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 08:22 PM
Are you using the ServiceNow email infrastructure?
If so, an email sent to your instance, containing 100mb of attachments would never even see your instance. There is a total limit on an email of 25mb through the email infrastructure (that includes the ~1.3-1.4x increase in size on attachments as transmitted due to Base64 MIME encoding typically seen on atttachments. See Email Size Restrictions.
Even if using private email infrastructure, you will likely face some size limits. Check with the email service administrator or documentation.
If the email does make through the infrastructure and to your instance, attachments are dropped prior to the inbound email actions running. The attachment has already been excluded and will not be in the table for you to locate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 08:22 PM
Are you using the ServiceNow email infrastructure?
If so, an email sent to your instance, containing 100mb of attachments would never even see your instance. There is a total limit on an email of 25mb through the email infrastructure (that includes the ~1.3-1.4x increase in size on attachments as transmitted due to Base64 MIME encoding typically seen on atttachments. See Email Size Restrictions.
Even if using private email infrastructure, you will likely face some size limits. Check with the email service administrator or documentation.
If the email does make through the infrastructure and to your instance, attachments are dropped prior to the inbound email actions running. The attachment has already been excluded and will not be in the table for you to locate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2016 08:50 PM
Thanks for your input. We do intend to use the OOTB infrastructure with the limit of attachment 25mb, however, once this is reached, the senders would like to receive a notification indicating one or more attachment have not been attached.
I have an new event created and is waiting for being fired off when total size of attachments reach the limit.
I am uncertain if the scripts after identifying oversized attachments can continue running.
Your advice is appreciated.
Kind regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 11:55 PM
Hi George/Dub,
I am trying to implement the exact same thing. Can you please provide more details on the scripts and its execution.
I was initially planning with a different approach, then the one described above.
Was planning to get a Scheduled script in place to run on a daily basis in off hours on the Email Log Entry table (syslog_email) to query for subject starts with "Maximum combined attachment size exceeded" and then accordingly trigger an Event which triggers a new notification.
Let me know your inputs on the same.
Thank you for your time.
Many Thanks,
Shahid Kalaniya.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2017 03:19 PM
Hi Shahid
As far as I can recall, the build I was trying to achieve was kind of complex as it involved with a lot of email related scripting e.g how email gets processed, how a new job gets created.
Below is the excerpt of my build proposal which hopefully could give you some guidance.
This build was eventually backed out due to script query overload which was investigated by HI despite it did achieve the functionality, however, it was a good lesson to learn about how email process works in ServiceNow.
Thanks Shahid.
Proposed build steps for Large Attachment Did Not Attach to HR Record (Notify end users if excessive size of emails detected)
Amend existing Script Include, TEST_InboundActionUtil (this is a custom Script Include )
Amend function appendAttachmentFileNames
Line 176 var header_div = '<div style="font-size:small; background-color:#D4D0C8; color:#000; font-family:Arial;"><ul>'; Line 189 var overSizeAttach = 'At least one attachment was not received due to excessive file size'; Line 198 if (this.checkAttachmentOversized(eml.sys_id)) attach_files += (isText) ? '\n' + overSizeAttach : '<li>' + overSizeAttach + '</li>'; line 210 } else if (this.checkAttachmentOversized(eml.sys_id)) { //gs.log('oversize attachment found'); eml.body = header_div + 'attachments were not attached due to excessive in size</ul></div><br/>' + eml.body; eml.u_appended = true;
} |
Amend function createRecord : function(address, user, desc, subj, email_uid, copy){
Add function, this function intends to check to see in syslog table against a specific email.sys_id if the log entry contains a certain string which is defined in Sys Properties table, email.inbound.attachment_size_reached_warn
checkAttachmentOversized: function (email_sys_id) {
var grMail = new GlideRecord('sys_email'); grMail.addQuery('sys_id', email_sys_id); grMail.addQuery('headers', 'CONTAINS', 'name='); grMail.query();
if (grMail.hasNext()) {
logger.logInfo('sys_email ' + email_sys_id + ' headers contain: name='); var max_attach_warn = gs.getProperty('email.inbound.attachment_size_reached_warn'); //logger.logInfo('max_attach_warn=' + max_attach_warn); var varLog = new GlideRecord('syslog'); var queryStr = 'sourceLIKE' + email_sys_id; queryStr += '^messageSTARTSWITH' + max_attach_warn; varLog.addEncodedQuery(queryStr); //logger.logInfo('searching: ' + queryStr); varLog.query(); //logger.logInfo(varLog.hasNext() ? 'log entry found' : 'log entry not found'); return varLog.hasNext(); } else { logger.logInfo('sys_email ' + email_sys_id + ' headers does not contain: name='); return false; } }, |
Add function, this function intends to trigger the email oversize notification by checking syslog table
fireOffOversizedEmailNotification: function (source_gr, recipient, subject) { var max_attach_warn = gs.getProperty('email.inbound.attachment_size_reached_warn'); fireOffOversizedEmailNotification: function (source_gr, email_sys_id, recipient) {
if (this.checkAttachmentOversized(email_sys_id)) { gs.eventQueue('systems_email_oversize.bounce', source_gr, recipient); return true; } else return false; } |
Add function, checkIfAttachmentInEmail
checkIfAttachmentInEmail: function (header_text) { return (header_text.indexOf('name=') > 0); } |
Create Event Registry
Event name | systems_email_oversize.bounce |
Table | Email [sys_email] |
Fired by | |
Description | Event: systems_email_oversize.bounce |
Create Event Notification
Name | (YOUR CORP NAME) Email Attachment Oversize Autorepl |
Table | Task [task] |
Description | Email Attachment Oversize autoreply - |
When to send | Send when: Event is fired Event name: systems_email_oversize.bounce |
Who will receive | Send to event creator: True |
What it will contain | Content type: HTML and plain text Subject: (Auto Reply): Attachments oversized ${number} |
Message HTML | Dear ${u_affected_contact.first_name}, Please be advised that the attachments in your email have reached the maximum size limit. The attachments have not attached to the original Job. Number: ${URI_REF} |
Create sys_properties record
Name | email.inbound.attachment_size_reached_warn |
Description | warning message prefix in email sys log when attachments reach the limit |
Choices | |
Type | String |
Value | Maximum combined attachment size exceeded |
End of build steps