Email is not sending to user

kummara _siva
Tera Contributor

Hi ,I have requirement to to send an email through code .

But not through the eventqueue or notifications only from code .

so I have created a record in sysemail table it is created a record but not sending mail to users .

here is the code I tried 

 var gr = new GlideRecord('sys_email');
 gr.initialize();
 gr.recipients ='kummarasivakumar.kanini@gmail.com';
 gr.subject = 'subjectss';
 gr.body = 'body';
 gr.type='sent';
 gr.insert();
Th
anks in Advance
2 ACCEPTED SOLUTIONS

Ehab Pilloor
Mega Sage

Hi @kummara _siva,

Try this:

 

var email = new GlideEmailOutbound();
email.setSubject("subjectss");
email.setBody("body");
email.addAddress("to","kumarasivakumar.kanini@gmail.com");
email.send();

 

 

If you found my response helpful, please mark it as Solution and Helpful.

 

Thanks and Regards,

Ehab

View solution in original post

Robbie
Kilo Patron
Kilo Patron

Hi @kummara _siva,

 

Is there any particular reason why you don't want to (or can't) trigger the email via events or notifications?

What about via Flow Designer / Workflow?

 

The only other way I could think of would be via the GlideEmailOutbound API.

 

Check the below link and article from @Vedhavrath_Kond who has explained this including emails very well - kudos.

 

(For future use and in case links break, here's the sample code, but I urge you to view the article.)

 

Example:

var mail = new GlideEmailOutbound();

mail.setReplyTo('agent@abc.com');

mail.setSubject('Testing outbound email'); 

mail.addAddress('cc', 'admin@example.com'); 

mail.setBody('Hello world!');

mail.save();

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

https://www.servicenow.com/community/developer-articles/glideemailoutbound-send-notifications-using-...

 

SN Docs link: https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/c_GlideEmai...

 

View solution in original post

2 REPLIES 2

Ehab Pilloor
Mega Sage

Hi @kummara _siva,

Try this:

 

var email = new GlideEmailOutbound();
email.setSubject("subjectss");
email.setBody("body");
email.addAddress("to","kumarasivakumar.kanini@gmail.com");
email.send();

 

 

If you found my response helpful, please mark it as Solution and Helpful.

 

Thanks and Regards,

Ehab

Robbie
Kilo Patron
Kilo Patron

Hi @kummara _siva,

 

Is there any particular reason why you don't want to (or can't) trigger the email via events or notifications?

What about via Flow Designer / Workflow?

 

The only other way I could think of would be via the GlideEmailOutbound API.

 

Check the below link and article from @Vedhavrath_Kond who has explained this including emails very well - kudos.

 

(For future use and in case links break, here's the sample code, but I urge you to view the article.)

 

Example:

var mail = new GlideEmailOutbound();

mail.setReplyTo('agent@abc.com');

mail.setSubject('Testing outbound email'); 

mail.addAddress('cc', 'admin@example.com'); 

mail.setBody('Hello world!');

mail.save();

 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

https://www.servicenow.com/community/developer-articles/glideemailoutbound-send-notifications-using-...

 

SN Docs link: https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/c_GlideEmai...