Remove Recipients from "TO" field and paste it in "BCC" field in the Email notifications

Kristin7
Tera Contributor

HI guys ,

I am trying to achieve a requirement to Remove the recipients from "TO" and display in "BCC" for all the Email notifications . I aware we can achieve this using the MAIL Script in the EMail notification .

So i wrote a mail script , to add the BCC , which is working ; but still "TO" field is getting populated too .

if (!current.watch_list.nil()) {
//get watch list addresses and add to bcc
var watcherIds = current.watch_list;
//get user records
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", "IN", watcherIds);
user.addQuery("email", "!=", "");
user.query();

while (user.next()) {
//add to cc list
email.addAddress("bcc", user.getValue('email'), user.getDisplayValue());

}
}

And one more issue is , we have around 80 Email notifications and we dont want to write Email scripts for each notification.

SO trying to write a Before Business Rule to query the sys_email table. And this action is only for Change and Problem table . And not for all notifications .

 

Need Help .

 

1 REPLY 1

Weston Wilson
Tera Expert

The only way to remove recipients is from the sys_email table. To add BCC users in the script, I was able to add recipients by using a mail script with a system property to specify which groups to add and an event parameter for users. There has to be at least one user specified in the "To" field or the email will not send. 

parm_arr = event.parm1.split(',');
//Loop through event parm1 list 
for (var i = 0; i < parm_arr.length; i++){
    if (parm_arr[i].indexOf('@') > -1){
        //Add email addresses to bcc list
        email.addAddress('bcc', parm_arr[i].toString(), parm_arr[i].toString());
        parm_arr.splice(i, 1);

        //decrement counter to adjust for new array length
        i = i-1; 
    }
}

var new_parm_str = parm_arr.toString();
//Find remaining parm1 users through sys_id
var bcc = new GlideRecord('sys_user');
bcc.addEncodedQuery('sys_idIN'+event.parm1);
bcc.query();

while (bcc.next()){
    email.addAddress('bcc', bcc.email.toStrinG(), bcc.user_name.toString());
}

var groups = gs.getProperty('sys.property.list.of.groups.sysids');
group_arr = groups.split(',');
for (var j = 0; j < group_arr.length; j++){
    var user_group = new GlideRecord('sys_user_grmember');
    user_group.addQuery('group', group_arr[j];
    user_group.query();

    while(user_group.next()){
        email.addAddress('bcc', user_group.user.email.toString(), user_group.user.user_name.toString());
    }
}