How to use @sendgrid/client - 9 common examples

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 Coding-Coach / find-a-mentor-api / src / modules / email / email.service.ts View on Github external
list_ids: [EmailService.LIST_IDS.MENTORS],
        contacts: [
          {
            email: contact.email,
            first_name: contact.name,
            country: contact.country,
            custom_fields: {
              // We can clean our list in SG with this field
              e2_T: isProduction ? 'production' : 'development',
            },
          },
        ],
      }),
    };

    return await sgClient.request(request);
  }
}
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);
  }
github NoQuarterTeam / split / packages / api / src / lib / mailer.ts View on Github external
async sendDev(args: MailArgs) {
    const request = {
      method: "GET",
      url: `/v3/templates/${args.templateId}`,
    }
    const [template] = await sendgridClient.request(request)
    const version = template.body.versions[template.body.versions.length - 1]
    const html = this.interpolateVariables(args.variables, version.html_content)
    const subject = version.subject
    const text = this.interpolateVariables(
      args.variables,
      version.plain_content,
    )
    this.devMail.sendMail({
      to: args.to,
      from: this.from,
      subject,
      html,
      text,
    })
  }
github iotexproject / iotex-explorer / src / server / gateways / get-sendgrid.ts View on Github external
sendgrid.addSubscription = async (
    email: string
  ): Promise<[ClientResponse, any]> => {
    request.body = [{ email }];
    return client.request(request);
  };
github sendgrid / sendgrid-nodejs / packages / mail / src / classes / mail-service.js View on Github external
constructor() {

    //Set client, initialize substitution wrappers and secret rules
    //filter
    this.setClient(new Client());
    this.setSubstitutionWrappers('{{', '}}');
    this.secretRules = [];
  }

@sendgrid/client

Twilio SendGrid NodeJS API client

MIT
Latest version published 20 days ago

Package Health Score

92 / 100
Full package analysis

Similar packages