小编uxt*_*xtx的帖子

在nodejs中模拟电子邮件功能

我已经建立了一个邮件程序功能,并试图加强覆盖范围.试图测试它的一部分已被证明是棘手的,特别是这个mailer.smtpTransport.sendMail

var nodemailer = require('nodemailer')

var mailer = {}

mailer.smtpTransport = nodemailer.createTransport('SMTP', {
    'service': 'Gmail',
    'auth': {
        'XOAuth2': {
            'user': 'test@test.com',
            'clientId': 'googleClientID',
            'clientSecret': 'superSekrit',
            'refreshToken': '1/refreshYoSelf'
        }
    }
})
var mailOptions = {
    from: 'Some Admin <test@tester.com>',
}

mailer.verify = function(email, hash) {
    var emailhtml = 'Welcome to TestCo. <a href="'+hash+'">Click this '+hash+'</a>'
    var emailtxt = 'Welcome to TestCo. This  is your hash: '+hash
    mailOptions.to = email
    mailOptions.subject = 'Welcome to TestCo!'
    mailOptions.html = emailhtml
    mailOptions.text = emailtxt
    mailer.smtpTransport.sendMail(mailOptions, …
Run Code Online (Sandbox Code Playgroud)

node.js nodemailer

17
推荐指数
2
解决办法
7151
查看次数

标签 统计

node.js ×1

nodemailer ×1