Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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',
};
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) {
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: "" });
}
})
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 }];
constructor() {
sgMail.setApiKey(Config.sendGrid.API_KEY);
sgClient.setApiKey(Config.sendGrid.API_KEY);
}