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

To help you get started, we’ve selected a few @sendgrid/mail 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 madhums / node-notifier / lib / notifier.js View on Github external
if(!/\@/.test(obj.to) || !/\@/.test(obj.from)) {
    throw new Error('Please specify proper to and from address');
  }

  if (this.config.service === 'postmark') {
    var Postmark = require('postmark');
    var postmark = new Postmark.ServerClient(this.config.key)
    options = {
      'From': obj.from,
      'To': obj.to,
      'Subject': obj.subject,
      'HtmlBody': html
    };
  } else if (this.config.service === 'sendgrid') {
    var sendgrid = require('@sendgrid/mail')
    sendgrid.setApiKey(this.config.key);
    options = {
      'to': obj.to,
      'from': obj.from,
      'subject': obj.subject,
      'html': html
    };
  }

  // as you don't want to send emails while development or testing
  if (process.env.NODE_ENV === 'test'
    || process.env.NODE_ENV === 'development') {
    // don't log during tests
    if (process.env.NODE_ENV !== 'test') {
      console.log(options);
    }
    cb();
github Lambda-School-Labs / CS10-restaurant-pos / api / controllers / employees / adminRegister.js View on Github external
const mjml2html = require('mjml').default;

const keys = require('../../../config/keys');

const sendGridKey = keys.sendGrid;
// For emails
const sgMail = require('@sendgrid/mail'); // eslint-disable-line

sgMail.setApiKey(sendGridKey);

// verifyFields verifies that all required fields are provided
const verifyFields = require('../../validation/verifyFields');
const Employee = require('../../models/Employee');

// @route   POST api/employees/admin/register
// @desc    Adds an administrator to the DB
// @access  Public
const adminRegister = (req, res) => {
  const {
    name, pass, email, images
  } = req.body;

  // Validate Fields
  const missingFields = verifyFields(['name', 'pass', 'email'], req.body, res);
github OriginProtocol / origin / infra / token-transfer-server / src / lib / email.js View on Github external
const template = require('lodash/template')
const sendgridMail = require('@sendgrid/mail')
const jwt = require('jsonwebtoken')
const mjml2html = require('mjml')
const Sequelize = require('sequelize')

const { User } = require('../models')
const {
  encryptionSecret,
  clientUrl,
  sendgridFromEmail,
  sendgridApiKey
} = require('../config')
const logger = require('../logger')

sendgridMail.setApiKey(sendgridApiKey)

// Load and compile the email templates.
const templateDir = `${__dirname}/../templates`
const welcomeTextTemplate = template(
  fs.readFileSync(`${templateDir}/welcome.txt`).toString()
)
const welcomeMjmlTemplate = template(
  fs.readFileSync(`${templateDir}/welcome.mjml`).toString()
)
const loginTextTemplate = template(
  fs.readFileSync(`${templateDir}/login.txt`).toString()
)
const loginMjmlTemplate = template(
  fs.readFileSync(`${templateDir}/login.mjml`).toString()
)
const transferTextTemplate = template(
github firebase / extensions / user-referral / functions / lib / index.js View on Github external
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const admin = require("firebase-admin");
const functions = require("firebase-functions");
const sgMail = require("@sendgrid/mail");
const assertions = require("./assertions");
const config_1 = require("./config");
const httpErrors = require("./errors");
const logs = require("./logs");
admin.initializeApp();
sgMail.setApiKey(config_1.default.sendgridApiKey);
logs.init();
exports.sendInvitation = functions.https.onCall((data, context) => __awaiter(this, void 0, void 0, function* () {
    logs.start();
    const { auth } = context;
    assertions.userIsAuthenticated(auth);
    try {
        const { uid } = auth;
        const { email } = data;
        logs.invitationCreating(config_1.default.invitationsCollection);
        const doc = yield admin
            .firestore()
            .collection(config_1.default.invitationsCollection)
            .add({
            senderUid: uid,
            email,
        });
github educatopia / educatopia / api / users.js View on Github external
),
  }

  function mailCallback (error, response) {
    if (error || !response) {
      console.error(error)
      done(error)
      return
    }

    console.info('Message sent: %s', response.messageId)
    done(null, response)
  }

  if (app.get('env') === 'production') {
    sendgrid.setApiKey(process.env.SENDGRID_API_KEY)
    sendgrid.send(mail, mailCallback)
  }
  else {
    nodemailer
      .createTransport()
      .sendMail(mail, mailCallback)
  }
}
github mmoskal / gitwed / server / mail.ts View on Github external
const sendgridSend: SendEmailFn = async (msg, config) => {
    sendGrid.setApiKey(config.sendgridApiKey)
    const res = await sendGrid.send(msg, false)
    return res[0].body
}
github xiaoshan5733 / cms / lib / mailer.js View on Github external
return new Promise((resolve, reject) => {
      sgMail.setApiKey(config.mail.options.key);
      const msg = {
        from,
        to,
        subject,
        html,
      };
      sgMail.send(msg, (err, res) => {
        if (!err) {
          resolve()
        } else {
          reject(err)
        }
      });
    })
  }
github looker / actions / src / actions / sendgrid / sendgrid.ts View on Github external
private sgMailClientFromRequest(request: Hub.ActionRequest) {
    sendgridMail.setApiKey(request.params.sendgrid_api_key!)
    return sendgridMail
  }
github pensieve-srs / pensieve-api / mailers / admin_mailer.js View on Github external
const text = require('./views/signup_alert.text.js');
const mailer = require('@sendgrid/mail');

const { classes: { EmailAddress } } = require('@sendgrid/helpers');

mailer.setApiKey(process.env.SENDGRID_API_KEY);

const adminEmail = process.env.ADMIN_EMAIL;
const adminAddress = new EmailAddress({ name: 'Pensieve', email: adminEmail });

module.exports.sendSignupAlert = user =>
  mailer.send({
    to: adminAddress,
    from: adminAddress,
    subject: 'New user alert! - You receive a new signup',
    text: text(user),
    html: text(user),
  });
github GetStream / Winds / api / src / utils / email / send.js View on Github external
export async function SendEmail(obj) {
	if (config.email.backend === 'sendgrid') {
		if (!config.email.sendgrid.secret) {
			throw new Error('Could not send reset email, missing Sendgrid secret.');
		}
		sendgrid.setApiKey(config.email.sendgrid.secret);
		let res = await sendgrid.send(obj);
		return res;
	} else {
		DummyEmailTransport.emails.unshift(obj);
		return obj;
	}
}

@sendgrid/mail

Twilio SendGrid NodeJS mail service

MIT
Latest version published 4 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages