Remove social media logo from incoming email signature

Aniko Hegedus
Tera Expert

Hi,

 

I was trying to find a solution to remove images from inbound email signatures. If someone has a Linkedin, Twitter, Facebook etc icon, they are all attached to the ticket and the agents have to open them one by one to check if they are valid attachments or not.

Servicenow recommends using the combination of these two properties to prevent this behaviour.

glide.email.inbound.image_sys_attachment.filter.minimum_bytes

glide.email.inbound.image_sys_attachment.filter.action

 

However, whatever minimum size you set, you can never be sure that you don't lose a real attachment or some icons can still get through. 

Therefore I came up with a solution that is working for us and even if it is not 100% according to your needs, it can give you inspiration. I realized that before all icons there's the platform's link, so I wrote a regex that finds the links, retrieves the sys id right after the link. With the sys_id you can find the attachment and delete it.

 

<span style="font-size:8.0pt;font-family:&quot;Arial&quot;,sans-serif;color:#727272;mso-ligatures:standardcontextual">&nbsp;&nbsp;</span><a href="https://www.linkedin.com/company/"><span style="font-size:10.5pt;font-family:Consolas;color:windowtext;text-decoration:none"><img border="0" width="18" height="18" style="width:.1875in;height:.1875in" id="Picture_x0020_12" src="/sys_attachment.do?sys_id=xxxxxxxx"></span></a>

 

I created a before insert business rule on the sys_email table that runs if the body contains Linkedin or Facebook etc. And the script is:

 

 

function findSysId(html, platform) {
        var platformRegex = new RegExp('href="https?://(?:www\\.)?' + platform + '\\.com/[^"]*"', 'i');
        var platformMatch = html.match(platformRegex);
        if (platformMatch) {
            var slicedHtml = html.slice(platformMatch.index);
            var sysIdRegex = new RegExp('sys_id=([a-f0-9]{32})', 'i');
            var sysIdMatch = slicedHtml.match(sysIdRegex);
            return sysIdMatch ? sysIdMatch[1] : null;
        }
        return null;
    }

    var imagesToBeDeleted = ["facebook", "youtube", "twitter", "linkedin", "flickr", "x"];
    for (var i = 0; i < imagesToBeDeleted.length; i++) {
        var sysId = findSysId(current.body, imagesToBeDeleted[i]);
        if (sysId) {
            deleteAttachment(sysId);
        }
    }

    function deleteAttachment(sysId) {
        var gr = new GlideRecord('sys_attachment');
        if (gr.get(sysId)) {
            gr.deleteRecord();
        }
    }

 

 

 

I hope it might help some of you.

Aniko

1 REPLY 1

Itellyon
Tera Contributor

If social media logos are added automatically to incoming emails, check your email parsing settings in ServiceNow or use a scripted email filter to remove them. Social media marketing often relies on consistent brand presence, so adjusting email content and automation can improve your overall strategy. For more info, explore ways to streamline email processing and social media integration!