|
| 1 | +// 📧 Email Bounce Alert Script |
| 2 | +// -------------------------------------------------------------- |
| 3 | +// Purpose: |
| 4 | +// This mail script detects bounced-back emails in the Junk module |
| 5 | +// and identifies recipient addresses from the email body. |
| 6 | +// |
| 7 | +// When a bounce is detected, it automatically triggers a notification |
| 8 | +// containing the affected email IDs and a link to the email record. |
| 9 | +// |
| 10 | +// Type: Email Script |
| 11 | +// Trigger: Notification |
| 12 | + |
| 13 | +(function runMailScript(current, template, email, email_action, event) { |
| 14 | + |
| 15 | + // --- Step 1: Function to extract email addresses from email body --- |
| 16 | + function extractEmails(html) { |
| 17 | + // Regular expression to match email patterns |
| 18 | + var emailPattern = /[\w\-]+@[\w\-]+/g; |
| 19 | + |
| 20 | + // Find all matching email addresses in the body |
| 21 | + var emails = html.match(emailPattern); |
| 22 | + |
| 23 | + // Return the array of emails or an empty array if none found |
| 24 | + return emails || []; |
| 25 | + } |
| 26 | + |
| 27 | + // --- Step 2: Convert the email body into plain text --- |
| 28 | + var body = current.body.toString().replaceAll('"', ''); |
| 29 | + |
| 30 | + // --- Step 3: Extract email addresses from the content --- |
| 31 | + var extractedEmails = extractEmails(body); |
| 32 | + |
| 33 | + // --- Step 4: Build the notification message --- |
| 34 | + template.print("This alert has been generated because a bounced email incident may have occurred due to possible IP blacklisting."); //example: IP blacklisting use case |
| 35 | + template.print("<br><strong>User(s) who missed the email:</strong> " + extractedEmails.join(', ')); |
| 36 | + template.print("<br><strong>Link to the bounced email record:</strong> "); |
| 37 | + template.print('<a href="' + gs.getProperty('glide.servlet.uri') + 'sys_email.do?sys_id=' + current.sys_id + '">Click here</a>'); |
| 38 | + |
| 39 | +})(current, template, email, email_action, event); |
0 commit comments