A module to simplify the connection to sendgrid for sending mail

Methods

(static) init(apiKey, from)

Initialize the Sendgrid module

Parameters:
NameTypeDescription
apiKeyString

Api key from sendgrid.

fromString

Standard from email address that will be used also as standard replyTo.

Since
  • 1.0.0
Author
  • Roel Voordendag
Example
const {Runtime, Server} = require('@neobeach/core');
const sendgrid = require('@neobeach/modules-sendgrid')

const server = new Server();

Runtime(() => {
   sendgrid.init(sendgridApiKey, 'noreply@dpdk.com');
   server.run();
});

(static) send(to, subject, text, html, replyToopt, ccopt, bccopt, attachmentsopt) → {Promise}

Helper function to send email with Sendgrid.

Parameters:
NameTypeAttributesDescription
toArray.<string> | String

String with email to send to or an array filled with email addresses the email will be sent to.

subjectString

Subject of the email.

textString

Text of the body of the mail.

htmlString

Body of email in html.

replyToString<optional>

Email address where replies to send email will be sent to (default from email).

ccArray.<string> | String<optional>

String with email to send to or an array filled with email addresses the email will be sent to.

bccArray.<string> | String<optional>

String with email to send to or an array filled with email addresses the email hidden will be sent to.

attachmentsArray<optional>

Array filled with needed object attachments information.

Since
  • 1.0.0
Author
  • Roel Voordendag
Returns:
Type: 
Promise
Example
const sendGrid = require('@neobeach/modules-sendgrid');

const response = await sendGrid.send({
   to: 'user@example.com',
   subject: 'Testing mail',
   text: 'This is a testing mail',
   html: '<p>This is a testing mail</p>',
   replyTo: 'replyToUser@example.com',
   cc: 'anotheruser@example.com',
   bcc: 'hiddenuser@example.com,
   attachments: []
 }}