How to use var email = new GlideEmailOutbound();

dev115415
Tera Expert

Hello I want to send an email from ServiceNow script include. The sender of email id will be for example sender1@gmail.com and receiver as receiver2@gmailcom. Can we use 

var email = new GlideEmailOutbound(); for this? How to use this.

7 REPLIES 7

Weird
Mega Sage

Yes, that should work. You'll just need to add the content:

 

var email = new GlideEmailOutbound();
email.setSubject("TEST");
email.setBody("LARGER TEST");
email.setFrom("testsender@test.com");
email.addRecipient("test@test.com");
email.save(); //EDIT: this was send, which is wrong

 


Note that Sender info might not work. It's dependent on how your email client has been configured. Sometimes they might show the sender you set in the header as a original-sender etc, but the client would automatically set from as the email client account.

Btw. you can also use setReplyTo() to set a reply to address and addAddress() to add recipients to cc or bcc.
For example addAddress("cc", "test@test.com") would add test to cc.

Ithink email.save(); is better 

 

email.save() is not just better as it's the correct way. Not sure why I wrote send, but that's wrong.

dev115415
Tera Expert

I was trying this but i do not know why is it not working