How to use var email = new GlideEmailOutbound();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 01:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 02:26 AM - edited 01-30-2024 03:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 12:21 PM
Ithink email.save(); is better
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2024 03:03 AM
email.save() is not just better as it's the correct way. Not sure why I wrote send, but that's wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 02:52 AM
I was trying this but i do not know why is it not working