sending an email from within a script

drslry2
Tera Contributor

Hi Gurus,

I'm attempting to run a script that updates a table then sends an email after the update.

The update of the table works fine, however the sending of the email does not.

The lines in bold below do not appear to be working properly.  

Can anyone tell me how to send an outbound email directly from a script?

Any info will be appreciated.

Thanks in advance!

var user = email.body.employee.toString();

var gr = new GlideRecord('sys_user');

gr.addQuery('email',user);  

gr.query();

gs.log(gr.getRowCount());

if (gr.next())

{

        gr.active = false;

        gr.update();

email.setFrom("umassmeddev@service-now.com");

email.setReplyTo("robert.poschmann@umassmed.edu");

email.setSubject("This is the new subject line");

email.setBody("This is the new body");

}

19 REPLIES 19

rjp
Tera Expert

I added the event to call the notifcation..



find_real_file.png


Here's my event...


find_real_file.png



and this is how I'm calling the event....


find_real_file.png



but its still not sending....



thanks for your patience.


can you try like,



gs.eventQueue('Update User Test', current, '3a5754b64f0ade00cdf248f18110c7b7');


Couple of things to check .



First   ,your gs.eventQueue seem to be wrong , you need to see what you are passing as parameters. Look at the syntax specified by Shishir.


Once you correct it , try again and if it is still not working check the following



1.Make sure ,you can see the incoming email in inbox.


2.Check the incoming mail   and check its log to see if any inbound action is triggered.


3.If you see that your inbound action is triggered , put some log statements in it and find out where is it failing .


4.Next , once all the above is checked and corrected , make sure you see the event triggered in event log. You can see the events in System Log   --> Events, if you see the event is triggered but no notifications ,then check the notification for any issues , if your event is not even in the log , then something wrong with inbound action which you will be able find out step by step as mentioned from #1 to #3.


rjp
Tera Expert

Hi JJ,


I'll follow your advice today.


rjp
Tera Expert

The inbound action is working but the notification is still not being sent.   This is what the event log shows for the event...it says it was processed.


this is the line in the inbound action, can i use the userid instead of the sys id?   Maybe that will help.




gs.eventQueue('Update User Test', current, '3a5754b64f0ade00cdf248f18110c7b7');



find_real_file.png