Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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");
});

大佬总结

以上是大佬教程为你收集整理的node.js – 节点邮件程序错误:“不支持的配置,将Nodemailer降级到v0.7.1以使用它”在localhost中全部内容,希望文章能够帮你解决node.js – 节点邮件程序错误:“不支持的配置,将Nodemailer降级到v0.7.1以使用它”在localhost中所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。