Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-mailjet' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const express = require('express')
const router = express.Router()
const User = require('../models/UserModel')
const jwt = require('jsonwebtoken')
const SHA512 = require('crypto-js/sha512')
const mailjet = require('node-mailjet')
.connect('5ef5f026c64d5e328dc7a113ba724e76', 'b4f9b9ec04a009f3da2167ddd0093a38')
router.post('/login', (req, res, next) => {
User.findOne({ username: req.body.username })
.then((player) => {
if (!player || SHA512(req.body.password) != player.password) {
res.sendStatus(403)
} else {
// TODO Exporter le secret dans la config
player.password = null
const token = jwt.sign({ user: player }, 'mysecretstory', { expiresIn: 3600 })
res.send({ token, user: player })
}
}, err => next(err))
})
private async mailjet(
subject: string, recipients: string, html: string, attachments: Attachments[]
): Promise {
const recipientList: Array<{ Email: string }> = recipients.split(",").map((emailAddress: string) => {
return { Email: emailAddress };
});
await mailjetConnect(
workspace.getConfiguration("mjml").mailjetAPIKey,
workspace.getConfiguration("mjml").mailjetAPISecret
).post("send").request({
"FromEmail": workspace.getConfiguration("mjml").mailSender,
"FromName": workspace.getConfiguration("mjml").mailFromName,
"Html-part": html,
"Inline_attachments": attachments,
"Recipients": recipientList,
"Subject": subject
}).then(() => {
window.showInformationMessage("Mail has been sent successfully.");
}).catch((error: any) => {
window.showErrorMessage(error.message);
});
}
constructor() {
this.api = require('node-mailjet').connect(config.email.mailjet.apiKey, config.email.mailjet.apiSecret);
}
function sendEmail(options) {
const mailjet = nodeMailjet.connect(mailjetConfig.apiKey, mailjetConfig.apiSecret);
return mailjet
.post('send')
.request(_formatPayload(options));
}
debug: boolean;
from: {
email: string;
name: string;
};
defaultSubject: string;
},
driverConfig: {
public: string;
private: string;
options: MailjetConnectOptionsInterface;
},
) {
this.config = generalConfig;
const connectOptions: MailjetConnectOptionsInterface = driverConfig.options;
this.mj = nodeMailjet.connect(driverConfig.public, driverConfig.private, {
version: 'v3.1',
...connectOptions,
});
}
async boot(): Promise {
const connectOptions: MailjetConnectOptionsInterface = this.configProvider.get('mail.connectOptions');
this.config = this.configProvider.get('mail.mailjet');
this.mj = nodeMailjet.connect(this.config.public, this.config.private, connectOptions);
}
'use strict'
const settings = require('nconf').get()
const mediaUtils = require('../src/lib/media')
const mailjet = require('node-mailjet').connect(settings.actions.mailjet.apiKey, settings.actions.mailjet.secretKey)
function run (options, request) {
return new Promise((resolve, reject) => {
if (!options.fromEmail && !settings.actions.mailjet.fromEmail) {
return reject({
error: 'missing parameter',
details: 'The "fromEmail" parameter is missing in the request.'
})
}
if (!options.recipients) {
return reject({
error: 'missing parameter',
details: 'The "recipients" parameter is missing in the request.'
})
}
if (!options.subject) {
export default function sendEmail(opts) {
const { content, Subject, APIKey, APISecret, SenderName, SenderEmail, TargetEmails } = opts
const mj = nodeMailjet.connect(APIKey, APISecret)
const send = mj.post('send')
const Recipients = TargetEmails.map(t => ({ Email: t }))
return send.request({
FromEmail: SenderEmail,
FromName: SenderName,
Subject,
'Html-part': content,
Recipients,
})
}
'use strict';
/**
* MailJet API for sending basic email
* @url https://dev.mailjet.com/guides/?javascript#sending-a-basic-email
*
* TODO: templates @url https://dev.mailjet.com/guides/?javascript#using-a-template
*/
const config = require('config');
const mailjet = require('node-mailjet').connect(
config.get('mailjet.api_key'),
config.get('mailjet.secret'),
);
const sendEmail = data =>
mailjet.post('send', { version: 'v3.1' }).request({
Messages: [
{
From: {
Email: data.fromEmail,
Name: data.fromName,
},
To: [
{
Email: data.to,
Name: data.nameTo,