Automatically flag emails as spam via flows

3 minutes de lecture
LWC

Introduction

Often when you implement « Email-To-Case » in your organisation, you will quickly be confronted with spam. Receiving a lot of spam can have an impact on your users’ time. Let’s see how we can automatically qualify incoming emails to flag them as spam and save your users time.

Requirements

To carry out the implementation you will need knowledge of the following topics:

  • Flow
  • Custom Metadata Type
  • Email-to-Case
  • Formula

Implementation

Create a Checkbox field IsSpam on the Case object

Checkbox Is spam field
Checkbox Is spam field

Create a Custom Metadata Type « Keyword »

This custom metadata type will contain all the keywords that we will use to search for them in the emails.

Custom metadata type Keywords
Custom metadata type Keywords

Here are some examples of keywords you can fill in

IMPORTANT: You must enter the keywords in capital letters.

List of keywords
List of keywords

To build your keyword base, you can look on the internet, many sites offer a list that you can use.

The Most Common Email Spam Words

Avoid these 250 trigger words to stop your emails going to spam

Building the flow

Presentation of the flow
Global presentation of the flow

1.Entry conditions

Nothing special about the entry conditions for the flow

Entry conditions of the flow
Entry conditions of the flow

Object : Case

When : A record is Created

Conditions : Origin Equals Email

Optimize the flow for : Fast Field Updates (Before)

 

2.Retrieving Keywords

We first need to get the keywords from the custom metadata type Keywords__mdt and loop over this object

Get records from keywords
Get records from keywords

We get the « Label » field which we will use to search for it in the email we receive.

Detail of loop
Detail of loop

 

3.Conditions for flagging the case as spam

In order to test if each of the keywords are found in the email we have created two formulas.

Formule : UpperDescription

UPPER({!$Record.Description})

This formula will be used to uppercase the content of the email in order to test the keywords and the content in capital letters only

Example :

  • « Test » == « TEST » => FALSE
  • UPPER(« Test ») == « TEST » => TRUE
UpperDescription Formula
UpperDescription Formula

Formule : IsSpam

CONTAINS({!UpperDescription} , {!Loop_keywords.Label})

We will search if each item of Keywords__mdt (Loop_keywords) is present in UpperDescription

IsSpam Formula
IsSpam Formula

Decision IsSpam ?

IsSpam Decision
IsSpam Decision

Flag the case as spam

Flag as SPAM
Flag as SPAM

 

When the case is flagged « SPAM » we stop directly, we do not need to continue with the other keywords.

Getting out from the loop
Getting out from the loop

Now you can test it and use it to flag incoming emails as spam :)

You can also use the notion of weight for your keywords for spam and if a case that is created with an email exceeds a certain weight, you can flag it as spam.

You can see my other articles here or read the latest blog posts here

A lire également sur le blog