本文整理汇总了TypeScript中nodemailer.createTransport函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createTransport函数的具体用法?TypeScript createTransport怎么用?TypeScript createTransport使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createTransport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor() {
let useSMTP = !!process.env.EMAIL_SMTP;
if (useSMTP) {
this.transporter = createTransport(process.env.EMAIL_SMTP);
} else {
// default to SES
if (process.env.EMAIL_SES) {
this.transporter = createTransport(sesTransport(JSON.parse(process.env.EMAIL_SES)));
} else {
this.transporter = createTransport(sesTransport({}));
}
}
}
示例2: constructor
constructor(generatorOptions, service?) {
service = service || 'gmail';
if(typeof generatorOptions === 'object'){
this.transporter = nodemailer.createTransport({
service: service,
auth: {
xoauth2: createXOAuth2Generator(generatorOptions)
}
});
} else {
this.transporter = nodemailer.createTransport(generatorOptions);
}
}
示例3: sendEmail
/**
* Sends an email.
*
* @param requestState
* @param {UserDocument} user Recipient
* @param {string} subject Subject of the email
* @param {string} template Name of the Handlebars template, without path or extension
* @param {object} templateData Data passed to the Handlebars renderer
* @param {string} [enabledFlag] If set, user profile must have this preference set to true
* @param {string} [emailAddress] If set, this email as the recipient's email instead of the user's default.
* @return Promise<SentMessageInfo>
*/
private async sendEmail(requestState: RequestState, user: UserDocument, subject: string, template: string, templateData: object, enabledFlag?: string, emailAddress?: string): Promise<SentMessageInfo> {
const what = template.replace(/-/g, ' ');
if (!this.emailEnabled(user, enabledFlag)) {
logger.info(requestState, '[mailer.sendEmail] NOT sending %s email to <%s>.', what, user.email);
return;
}
// generate content
const tpl = await this.getTemplate(template);
const text = this.wrap(tpl(templateData), 60);
// setup email
const email: Mail.Options = {
from: { name: config.vpdb.email.sender.name, address: config.vpdb.email.sender.email },
to: { name: user.name, address: emailAddress || user.email },
subject,
text,
};
// create reusable transporter object using the default SMTP transport
const transport = nodemailer.createTransport(config.vpdb.email.nodemailer);
logger.info(requestState, '[mailer.sendEmail] Sending %s email to <%s>...', what, (email.to as Address).address);
const status = await transport.sendMail(email);
if (status.messageId) {
logger.info(requestState, '[mailer.sendEmail] Successfully sent %s mail to <%s> with message ID "%s" (%s).', what, (email.to as Address).address, status.messageId, status.response);
} else {
logger.info(requestState, '[mailer.sendEmail] Failed sending %s mail to <%s>: %s.', what, (email.to as Address).address, status.response);
}
return status;
}
示例4:
.https.onCall(async (data) => {
const transporter = nodemailer.createTransport({
host: 'mail.sfwinterbach.com',
port: 465,
secure: true,
auth: {
user: functions.config().mailer.email,
pass: functions.config().mailer.password
}
});
const fromName = 'Kontakt';
const fromEmail = 'kontaktformular@sfwinterbach.com';
const to = data.to;
const text = data.text;
const mailOptions = {
from: fromName + ' <' + fromEmail + '>',
to: to,
subject: 'Anfrage auf ' + transporter.host,
text: text,
html: text,
};
const info = await transporter.sendMail(mailOptions);
console.log('Message sent: %s', info.messageId);
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
console.log(info);
return info;
});
示例5: email_request
// EMAIL VERIFICATION
async function email_request(req, res, next) {
try {
let found_user:any = await pendingUser.findOne({ _id: req.body.user_id })
if(!found_user) return res.status(500).send({message: 'User not found'})
let duplicate_user:any = await pendingUser.findOne({ email: req.body.email })
let email_in_use = false
if(duplicate_user) email_in_use = duplicate_user.social_id !== found_user.social_id
if(await realUser.findOne({ email: req.body.email }) || email_in_use || found_user.email_verified ) return res.status(500).send({ message: 'The email adress is already getting used' })
let token:any = new emailToken({ user_id: found_user._id, token: crypto.randomBytes(16).toString('hex') })
await token.save()
found_user.email = CryptoJS.AES.encrypt(req.body.email, process.env.DECRYPT_KEY);
await found_user.save()
let confirmation_link = process.env.NODE_ENV === 'production' ? `https://signup.utopian.io` : `http://localhost:${process.env.REGISTRATION_FRONTEND_PORT}`
let transporter = nodemailer.createTransport({ host: 'smtp.gmail.com', port: 465, secure: true, auth: { user: process.env.GOOGLE_MAIL_ACCOUNT, pass: process.env.GOOGLE_MAIL_PASSWORD } })
let mailOptions = { from: process.env.GOOGLE_MAIL_ACCOUNT, to: req.body.email, subject: 'Utopian Email Confirmation', text: 'Hey there,\n\n' + `Please confirm your email for Utopian.io by clicking on this link: ${confirmation_link}/email/confirm/${token.token}` + '.\n' }
await transporter.sendMail(mailOptions)
res.status(200).send('A verification email has been sent to ' + found_user.email + '.')
} catch (error) {
console.error(error.message)
res.status(500).json({ message: filter_error_message(error.message)})
}
}
示例6: sendEmail
static sendEmail(mailOptions) {
const email = encodeURIComponent(functions.config().smtp.email);
const password = encodeURIComponent(functions.config().smtp.password);
const mailTransport = nodemailer.createTransport(
`smtps://${email}:${password}@authsmtp.uchicago.edu`,
);
return new Promise(resolve => mailTransport.sendMail(mailOptions, resolve));
}
示例7: replyTemplate
export const sendReplyEmail = (address: IAddress) => {
if (transporter == null) {
transporter = nodemailer.createTransport({
/**
* 采用连接池链接,节省资源
*/
pool: true as any,
/**
* qq 邮箱配置文档
* http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=331
*/
host: 'smtp.qq.com',
port: 587,
// secure: true,
auth: {
user: process.env.QQSMTP_USER,
pass: process.env.QQSMTP_PASS,
}
})
}
const html = replyTemplate(address.data)
log.info('sendEmail.ready', {
address,
html
})
let mailOptions = {
/**
* 发件人,email 必须和 user 一致
*/
from: `Said <${process.env.QQSMTP_USER}>`, // sender address
/**
* 收件人,多个人使用 , 号分割
* mailer@nodemailer.com, Mailer <mailer2@nodemailer.com>
*/
to: address.to, // list of receivers
/**
* 标题
*/
subject: address.subject, // Subject line
/**
* 邮件正文
*/
html, // html body
}
/**
* 发送邮件
*/
transporter.sendMail(mailOptions).then(messageInfo => {
log.info('sendEmail.success', messageInfo)
}).catch(err => {
log.error('sendEmail.error', err)
})
}
示例8: setup
async setup () {
// create reusable transporter method (opens pool of SMTP connections)
this.insert(nodemailer.createTransport(this.config.transport))
if (this.config.plugins) {
for (let pluginKey of Object.keys(this.config.plugins)) {
this.app.nodemailer.use(pluginKey, this.config.plugins[pluginKey])
}
}
await this.app.nodemailer.verify()
}
示例9: sendResetMail
export function sendResetMail(to, from, content, options, done) {
var smtpTransport = nodemailer.createTransport(options);
var mailOptions = {
to: to,
from: from,
subject: "Password Reset",
html: content
};
smtpTransport.sendMail(mailOptions, (err) => {
return done(err);
});
}
示例10: function
router.post('/contact', function (req, res) {
console.log("Contact information " + req.body.name + " " + req.body.email + " " + req.body.message);
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: config.mail
});
config.mailOptions.subject = 'Cleaning customer ' + req.body.name;
config.mailOptions.text = req.body.message + "\n" + "From: " + req.body.email;
transporter.sendMail(config.mailOptions, function (error, info) {
/// res.redirect("/");
});
});
示例11:
postman.init = () => {
const email = mailer.createTransport({
service: appConfig.smtp_service.name,
auth: {
user: appConfig.smtp_service.username,
pass: appConfig.smtp_service.password
}
});
postman._email = email;
};
示例12:
nodemailer.createTestAccount((_err, _account) => {
const transporter = nodemailer.createTransport(config.mail);
// setup email data with unicode symbols
const mailOptions = {
from: `"RAP2 Notifier" <${config.mailSender}>`, // sender address
to,
subject,
html,
};
// send mail with defined transport object
transporter.sendMail(mailOptions)
})
示例13: getTransport
export async function getTransport (): Promise<nodemailer.Transporter> {
try {
let config = await getMailConfig(process.env.NODE_ENV || 'development')
let logger = getLogger(config.logfile)
let transport = nodemailer.createTransport(mailGun({
auth: {
api_key: config.api_key,
domain: config.domain
},
logger: logger
}))
return transport
} catch (err) {
throw err
}
}
示例14: function
sendEmail: function (to: string, subject: string, content: string, callback: void) {
var mailer = require("nodemailer");
var smtpTransport = mailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: 'tuananhdev200898@gmail.com',
pass: 'ttlpta840465'
}
});
var mailOptions = {
to: to,
subject: subject,
text: content
};
smtpTransport.sendMail(mailOptions, callback);
},
示例15: constructor
constructor() {
super();
this.smtpOptions = {
host: Mailer.host,
port: Mailer.port,
secure: Mailer.secureConnection,
auth: {
user: Mailer.username,
pass: Mailer.password,
},
requireTLS: Mailer.requireTLS,
};
this.transporter = Nodemailer.createTransport(this.smtpOptions);
this.validator = new Validator();
this.emailTemplates = new EmailTemplates();
}