How to use the @sendgrid/mail.send 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 jpchip / giveaway-grabber / src / giveaways.js View on Github external
if (
				process.env.SENDGRID_API_KEY &&
				process.env.SENDGRID_API_KEY !== ''
			) {
				sgMail.setApiKey(process.env.SENDGRID_API_KEY);
				const msg = {
					to: process.env.AMAZON_USERNAME,
					from: process.env.AMAZON_USERNAME,
					subject: 'giveaway-grabber: You won!',
					text: winningEntryUrl
				};
				if (process.env.SENDGRID_CC && process.env.SENDGRID_CC !== '') {
					msg.cc = process.env.SENDGRID_CC;
				}
				console.log('sending email');
				await sgMail.send(msg);
			}
			//Store that we won
			await setProcessingCode(urlTypes.WIN, currentGiveawayUrl);
		} else {
			// Store that we lost
			await setProcessingCode(urlTypes.LOST, currentGiveawayUrl);
		}
		return true;
	} catch (error) {
		console.log('could not get result, oh well. Moving on!');
		return false;
	}
}
github OriginProtocol / origin / infra / bridge / src / utils / log-chat.js View on Github external
}

  const username = String(message.from.username || message.from.id)
  const messageText = message.text

  const email = {
    to:
      process.env.TELEGRAM_BOT_EMAIL ||
      'support+telegram-bot@originprotocol.com',
    from: process.env.SENDGRID_FROM_EMAIL,
    subject: `${username} has replied to Telegram Bot`,
    text: `> ${messageText}`
  }

  try {
    await sendgridMail.send(email)
  } catch (error) {
    logger.error(`Could not send email via SendGrid: ${error}`)
  }

  // Insert to DB
  await TelegramChatLog.create({
    rawPayload: message,
    message: messageText,
    userId: message.from.id,
    username
  })

  logger.debug('Logged chat from ', username)
}
github Lambda-School-Labs / CS9-KnowledgeRocket / server / mail / MailRouter.js View on Github external
personalizations,
            template_id: SG_TEMPLATE_ID,
            from: { email: 'noreply@krocket.com' },
            subject: `Knowledge Rocket: ${subject}`,
        });

        // DANGER
        // INEFFECIENT
        const [twoDayEmails, twoWeekEmails, twoMonthEmails] = emails.map(email =>
            email.map(handleEmailCreation(createPersonalization, createEmail))
        );

        const emailBatch = [
            sgMail.send(twoDayEmails),
            sgMail.send(twoWeekEmails),
            sgMail.send(twoMonthEmails),
        ];

        try {
            await Promise.all(emailBatch);
            res.json({
                success: true,
            });
        } catch (error) {
            res.json({
                error,
                success: false,
            });
        }
    } catch (err) {
        res.json({
            err,
github OriginProtocol / origin / infra / token-transfer-server / src / login.js View on Github external
process.env.ENCRYPTION_SECRET,
      { expiresIn: '5m' }
    )

    const data = {
      to: email,
      from: emailFrom,
      subject: 'Your T3 verification code',
      text: `Welcome to the Origin Investor Portal. Here is your single-use sign in link.

        ${process.env.PORTAL_URL ||
          'http://localhost:3000'}/login_handler/${token}.

        It will expire in 5 minutes. You can reply directly to this email with any questions.`
    }
    await sendgridMail.send(data)
    logger.info(`Sent email code to ${email}`)
  } else {
    // Do nothing in case email not found in our DB.
    // But do not let the caller know by returning anything different,
    // to avoid tipping them on whether or not the email exists.
    logger.info(`Email ${email} not found in DB. No code sent.`)
  }

  res.setHeader('Content-Type', 'application/json')
  res.send(JSON.stringify({ email }))
}
github CommerceQL / commerceql / oldsrc / sendOrderEmail.ts View on Github external
return new Promise((resolve, reject) => {
    sgMail
      .send(message)
      .then(() => {
        return resolve()
      })
      .catch(error => {
        console.log('Email could not be sent because an error occured:')
        console.log(error)

        return resolve({ error: error.message })
      })
  })
}
github jbergant / chatbot-facebook-v2-final / app.js View on Github external
function sendEmail(subject, content) {
	console.log('sending email!');
    const sgMail = require('@sendgrid/mail');
    sgMail.setApiKey(config.SENGRID_API_KEY);
    const msg = {
        to: config.EMAIL_TO,
        from: config.EMAIL_FROM,
        subject: subject,
        text: content,
        html: content,
    };
    sgMail.send(msg)
		.then(() => {
        console.log('Email Sent!');
    })
	.catch(error => {
		console.log('Email NOT Sent!');
		console.error(error.toString());
	});

}
github rezendi / ykarma / server / routes / emails.js View on Github external
Your reward ${util.getRewardInfoFrom(reward)}
was just sold to ${buyerInfo}
You should connect with them to give them the reward!

YKarma
https://www.ykarma.com/
`,
    html: `
<p>Your reward <b>${util.getRewardInfoFrom(reward)}</b></p>
<p>was just sold to <b>${buyerInfo}</b></p>
<p>You should connect with them to give them the reward!</p>
<hr>
<a href="https://www.ykarma.com/">YKarma</a>
`,
  };
  sgMail.send(msg);
}
github BigDataBoutique / ElastiQuill / backend / src / services / emails.js View on Github external
from: config.blog["comments-noreply-email"],
    subject,
    html: `
    <div>      
      ${
        args.opComment
          ? `<h3>New reply to your comment on <a href="${args.opUrl}">blog post</a>:</h3>` +
            renderComment(args.opComment)
          : `<h3>New reply to your post <a href="${args.opUrl}">${args.opTitle}</a></h3>`
      }
      ${renderComment(args.comment)}
    </div>
    `,
  };

  sgMail.send(msg);
}
github patrickmichalina / fusing-angular-v1-archived / src / server / services / email.service.ts View on Github external
send(mailData: MailData) {
    return fromPromise(sendGrid.send(mailData))
  }
github rezendi / ykarma / server / scripts / cron.js View on Github external
You now have 100 more YKarma to give away!
Log into https://www.ykarma.com/ to give it to the deserving or even the not-so-deserving.
These expire in a month or so, so give them away soon --

YKarma
https://www.ykarma.com/
`,
    html: `
<p>You now have 100 more YKarma to give away!</p>
<p><a href="https://www.ykarma.com/">Log in to YKarma</a> to give it to the deserving or even the not-so-deserving.</p>
<p>These expire in a month or so, so give them away soon --</p>
<hr>
<a href="https://www.ykarma.com/">YKarma</a>
`,
  };
  sgMail.send(msg);
}

@sendgrid/mail

Twilio SendGrid NodeJS mail service

MIT
Latest version published 4 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages