Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Define Multiple Outbound Email Accounts according to Department

F_bio Gon_alves
Tera Expert

Hi SNC,

As anyone managed to successfully set multiple Outbound Email Accounts according to Department?

For example, for a given email notification sent to user A regarding Facilities Request closure, tthe outbound email be presented as 'facilities@companyA.com'; and for an email notification sent to user B regarding Marketing Request closure, the outbound email be presented as 'marketing@companyB.com'?

Thanks in advance,

Fábio Gonçalves

1 ACCEPTED SOLUTION

Hi Fabio,



I am not sure on your intent of having GR query on sysevent_email_action table, you have to create mail scripts under the 'Notification mail scripts' module



find_real_file.png



you have to use the email.setFrom in the mail script and use the email script in the notification as ${mail_script:<mail script name>}



http://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#gsc.tab=0


View solution in original post

9 REPLIES 9

karthik73
Mega Guru

Hi Fabio,



You should be able to do that with a mail script,



email.setFrom('email@email.com');



additionally, you may want to set the forwarding rules/set reply to on the email (email.setReplyTo('email1@email1.com')), so you ensure the replies to the emails sent are received and processed (if you expect any inbound emails)


Hi Karthik,



Thanks for your help.



That is the Email script I created. But, for some reason, it do not work:



"


(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,


  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,


  /* Optional GlideRecord */ event) {




var emailNotification = new GlideRecord("sysevent_email_action.list");


emailNotification.addEncodedQuery('active=true^collectionSTARTSWITHhr^ORcollectionSTARTSWITHfacilities^ORcollectionSTARTSWITHsn_sm_finance^ORcollectionSTARTSWITHsn_sm_legal^ORcollectionSTARTSWITHsn_sm_marketing');


emailNotification.query();




while (emailNotification.next()) {



  if (emailNotification.collection.startsWith('hr')) {


  email.setFrom('recruiting@example.com');


  }



  if (emailNotification.collection.startsWith('facilities')) {


  email.setFrom('security@example.com');


  }



  if (emailNotification.collection.startsWith('sn_sm_finance')) {


  email.setFrom('finance@example.com');


  }



  if (emailNotification.collection.startsWith('sn_sm_legal')) {


  email.setFrom('legal@example.com');


  }



  if (emailNotification.collection.startsWith('sn_sm_marketing')) {


  email.setFrom('marketing@example.com');


  }


}


})(current, template, email, email_action, event);"




Any ideas?



Thanks in advance,



Fábio Gonçalves


Hi Fabio,



I am not sure on your intent of having GR query on sysevent_email_action table, you have to create mail scripts under the 'Notification mail scripts' module



find_real_file.png



you have to use the email.setFrom in the mail script and use the email script in the notification as ${mail_script:<mail script name>}



http://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#gsc.tab=0


Hi again Karthik.



Thank you again.



Just one last question: where should I se the email script in the notification as ${mail_script:<mail script name>}? In which field/section of the Email Notification should I include this code?




Thank you.




Fábio Gonçalves