Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
nodemailer.createTestAccount((err, mailAcc) => {
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: process.env.smtp,
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: process.env.nodemailerEmail, // generated ethereal user
pass: process.env.nodemailerPw // generated ethereal password
}
});
console.log(process.env.nodemailerEmail, process.env.nodemailerPw);
// setup email data with unicode symbols
const mailOptions = {
from: process.env.nodemailerEmail, // sender address
to: email, // list of receivers
subject: `thanks for signing up (: `, // Subject line
function getEtherealTransportUnCached() {
return createTestAccount().then(auth =>
createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth,
}),
);
}
let testTransport: null | Promise = null;
async createTransporter() {
if (process.env.NODE_ENV === 'development') {
const {
smtp: { host, port, secure },
user,
pass,
} = await nodemailer.createTestAccount();
this.transporter = nodemailer.createTransport({
host,
port,
secure,
auth: { user, pass },
});
} else {
this.transporter = nodemailer.createTransport({
// TODO: provide a production info here
});
}
return this.transporter;
}
const sendVerificationMail = async () => {
try {
const emailBody = await prepareEmailBody();
const account = await nodemailer.createTestAccount();
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
// setup email data with unicode symbols
const mailOptions = {
from: '"Fred Foo 👻" ', // sender address
to: 'shindesharad71@gmail.com', // list of receivers
subject: "Hello ✔", // Subject line
private async boot(): Promise {
// create transport with settings
if (this.CONFIG.testing) {
createTestAccount((err, account) => {
if (err != null) {
this.logger.warn("testingAccount.creation.error", err);
throw err;
} else {
this.logger.trace("testingAccount.creation.success", account.user);
}
this.createTransport({
host: account.smtp.host,
port: account.smtp.port,
secure: account.smtp.secure,
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
}
});
export const sendEmail = async (params: IMailerParams) => {
const account = await nodemailer.createTestAccount()
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
// true for 465, false for other ports
secure: false,
auth: {
user: account.user,
pass: account.pass,
},
})
const mailOptions = {
from: params.from,
to: params.to,
subject: params.subject,
export async function MailerCredentials(): Promise {
const { MAIL_HOST, MAIL_PORT, MAIL_USER, MAIL_PASS, ENVIRONMENT } = defaults;
const config: MailConfig = {
host: MAIL_HOST,
port: MAIL_PORT,
auth: {
user: MAIL_USER,
pass: MAIL_PASS,
},
};
if (ENVIRONMENT !== 'production' && !MAIL_USER && !MAIL_PASS) {
const { user, pass } = await nodemailer.createTestAccount();
config.auth.user = user;
config.auth.pass = pass;
}
return config;
}