微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node.js – 节点邮件程序错误:“不支持的配置,将Nodemailer降级到v0.7.1以使用它”在localhost中

我是nodejs的新手,并尝试从nodemailer模块发送邮件,但它有错误,即“不支持的配置,将Nodemailer降级到v0.7.1以使用它”.

这是我的代码: –

var nodemailer = require('nodemailer');
var mailTransport = nodemailer.createTransport('SMTP',{
    service: 'Gmail',auth: {
        user: 'xxxxxxxx@gmail.com',pass: 'xxxxxxxxx',}
});

mailTransport.sendMail({
    from: '"ABC" <info@xxxx.example.com>',to: 'abcsss@xxx.example.com',subject: 'Test',text: 'Thank you for contact.',},function (err) {
    if (err)
        console.error('Unable to send email: ' + err);
});

解决方法

要使用nodemailer v1,请尝试实现此代码.

var express = require('express');
var nodemailer = require("nodemailer");
var smtpTransport = require("nodemailer-smtp-transport")
var app = express();

var smtpTransport = nodemailer.createTransport(smtpTransport({
    host : "YOUR SMTP SERVER ADDRESS",secureConnection : false,port: 587,auth : {
        user : "YourEmail",pass : "YourEmailPassword"
    }
}));
app.get('/send',function(req,res){
    var mailOptions={
        from : "YourEmail",to : "Recipient'sEmail",subject : "Your Subject",text : "Your Text",html : "HTML GENERATED",attachments : [
            {   // file on disk as an attachment
                filename: 'text3.txt',path: 'Your File path' // stream this file
            }
        ]
    }
    console.log(mailOptions);
    smtpTransport.sendMail(mailOptions,function(error,response){
        if(error){
            console.log(error);
            res.end("error");
        }else{
            console.log(response.response.toString());
            console.log("Message sent: " + response.message);
            res.end("sent");
        }
    });
});

app.listen(3000,function(){
    console.log("Express Started on Port 3000");
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐