Send email in BCC to multiple users

nk_dubey1
Kilo Contributor

Hi,

 

I have a requirement to send email in BCC. I have business rule which query user table and fetch all email ID's and saved it as a comma separate text. As of now It's working fine but all email going on To.

 

I want to send all email in BCC instead of To. I can't use email.addAddress("bcc", "john.secret@example.com","John Roberts"); as this will send email to only one. I have more than 1000+ users who is receiving email, in this case 1000+ emails will be triggered.

 

Do we have any function in SN which sends email in BCC with comma separated values.

 

Regards,

ND

1 ACCEPTED SOLUTION

prasanna_paulra
ServiceNow Employee
ServiceNow Employee

Hi ND,



You can make use of while loop, suppose if you want to add all users in incident watch list to bcc,


you can use the below code in your notification.



var watcherIds = current.watch_list.split(",");


//get user records


var user = new GlideRecord("sys_user");


user.addQuery("sys_id", watcherIds);


user.addQuery("notification", 2); //email


user.addQuery("email", "!=", "");


user.query();


while (user.next()) {


//add to bcc list


email.addAddress("bcc", user.email, user.getDisplayValue());


}



Hope this helps.



Thanks,


Prasanna


View solution in original post

3 REPLIES 3

prasanna_paulra
ServiceNow Employee
ServiceNow Employee

Hi ND,



You can make use of while loop, suppose if you want to add all users in incident watch list to bcc,


you can use the below code in your notification.



var watcherIds = current.watch_list.split(",");


//get user records


var user = new GlideRecord("sys_user");


user.addQuery("sys_id", watcherIds);


user.addQuery("notification", 2); //email


user.addQuery("email", "!=", "");


user.query();


while (user.next()) {


//add to bcc list


email.addAddress("bcc", user.email, user.getDisplayValue());


}



Hope this helps.



Thanks,


Prasanna


nk_dubey1
Kilo Contributor

Thanks for reply.



I just did same thing.



Regards,


ND


derekjohnson1
Kilo Contributor

how do you do this for any notification? seems like above is related to watch list, but i'd want it just for any/all recipients for certain notifications.