How to use the @sendgrid/client.setApiKey function in @sendgrid/client

To help you get started, we’ve selected a few @sendgrid/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sendgrid / sendgrid-nodejs / packages / contact-importer / src / importer.spec.js View on Github external
beforeEach(function() {
    // Create a new Twilio SendGrid instance.
    const API_KEY = process.env.API_KEY;
    sendgrid.setApiKey(API_KEY);

    // Create a new importer with a batch size of 2.
    this.contactImporter = new ContactImporter(sendgrid, {
      batchSize: 2,
    });
    // this.spy = sinon.spy(ContactImporter.prototype, '_sendBatch')
    this.sinon.spy(ContactImporter.prototype, '_sendBatch');

    // Generate some test data.
    const data = [];
    for (i = 0; i < 5; i++) {
      const item = {
        email: 'example' + i + '@example.com',
        first_name: 'Test',
        last_name: 'User',
      };
github NoQuarterTeam / split / packages / api / src / lib / mailer.ts View on Github external
import sendgrid from "@sendgrid/mail"
import sendgridClient from "@sendgrid/client"
import nodemailer, { Transporter } from "nodemailer"

import { SENDGRID_API_KEY, devEmailOptions, isProduction } from "./config"

sendgrid.setApiKey(SENDGRID_API_KEY)
sendgridClient.setApiKey(SENDGRID_API_KEY)

interface MailArgs {
  templateId: string
  to: string[] | string
  variables?: any
}

export class Mailer {
  private readonly from: string = "Split Team "
  private devMail: Transporter

  constructor() {
    this.devMail = nodemailer.createTransport(devEmailOptions)
  }

  send(args: MailArgs) {
github jake-101 / bael-template / src / sendgrid / app.js View on Github external
exports.handler = function(event, context, callback) {
  const {
    SENDGRID_API_KEY,
    SENDGRID_WELCOME_SENDER_EMAIL,
    SENDGRID_WELCOME_SENDER_NAME,
    SENDGRID_WELCOME_TEMPLATE_ID
  } = process.env;
  const body = JSON.parse(event.body);
  const email = body.email;
  const welcomeEmail = event.queryStringParameters.welcome_email === "true";

  client.setApiKey(SENDGRID_API_KEY);
  addSendgridRecipient(client, email)
    .then((response, body) => {
      if (welcomeEmail) {
        sendWelcomeEmail(
          client,
          email,
          SENDGRID_WELCOME_SENDER_EMAIL,
          SENDGRID_WELCOME_SENDER_NAME,
          SENDGRID_WELCOME_TEMPLATE_ID
        )
				.then(response => callback(null, { statusCode: response.statusCode, body: email + " added" }) )
				.catch(err => callback(err, null));
      } else {
        callback(null, { statusCode: response.statusCode, body: "" });
      }
    })
github iotexproject / iotex-explorer / src / server / gateways / get-sendgrid.ts View on Github external
export function getSendgrid(opts: any): any {
  const gateways: GatewaysConfig = config.get("gateways");

  client.setApiKey(gateways.sendgridApiKey);

  const sendgrid = {
    ...opts,
    apiKey: gateways.sendgridApiKey,
    client
  };
  const request: ClientRequest = {
    method: sendgrid.method,
    url: sendgrid.url,
    body: []
  };

  sendgrid.addSubscription = async (
    email: string
  ): Promise<[ClientResponse, any]> => {
    request.body = [{ email }];
github Coding-Coach / find-a-mentor-api / src / modules / email / email.service.ts View on Github external
constructor() {
    sgMail.setApiKey(Config.sendGrid.API_KEY);
    sgClient.setApiKey(Config.sendGrid.API_KEY);
  }

@sendgrid/client

Twilio SendGrid NodeJS API client

MIT
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis