Business rule to prevent emails sending to system users

georgechen
Kilo Guru

Hi folks,

I am trying to brainstorm the idea of creating a new business rule on sys_email table before condition, but wonder if anyone has thought of the similar idea.

Name: (Test) Prevent emails sent to users with conditions

Table: Email [sys_email]

Active: True

Condition:   !current.instance.nil() && current.type=='send-ready' && current.weight > '0'

Script:  

preventSendingEmails();

function preventSendingEmails() {

/*   some conditions checking

      Checking 1:   Email contains NOADDRESS

      Checking 2:   Email contains DUPLICATE

      Checking 3:   Email notification = 1 (None)

*/

current.type = 'send-ignored';

}

Any input would be appreciated

5 REPLIES 5

Ben Collyer
Giga Guru

re:Checking 1 - Do you mean the email address is an empty string?   Or do you mean it contains the text 'NOADDRESS'?



re:Checking 2 - Do you mean the email is a duplicate of another email in the system?   Or do you mean it contains the text 'DUPLICATE'?



Your requirements are not clear sorry.


Hi Ben



Actually we ended up finding an OOTB plug-in Email Filters which does exactly what we are after.   The Filter enables to set up conditions and also the action taken to deal with the emails.




151214_Email_Filters.PNG



This feature transcends the Business Rule I intended to create, and I am testing this.



Hope you are setting down all good at your new role.



Cheers


I found this post while trying to achieve a similar thing. We are trying to prevent our client's instance from sending outbound emails to six specific email addresses. I have copied the above email flitter script exactly and made the appropriate changes to target the six email addresses. Three of the addresses did not have an email get sent while three did still get sent. I am a novice with scripting so I am thinking I may need to change what scripting I am using. 

Hey Erik,

You don't really need a script to do this.  Create a new business rule like:

email1.jpg

I've only added 3 bad email addresses, but you can add as many as needed.  Then set the Actions tab like:

email2.jpg

Then any emails which are inserted ready for sending, but which contain any of the 6 bad email addresses, will skip sending and move to "send-ignore".

 

Be aware that emails to multiple addresses, any of which are one of the 6 bad addresses, will be entirely prevented from sending.  So the "good" email addresses on the same emails won't get the email either. If you have good and bad addresses on the same email then you will need a script to only remove the bad ones.