登录
注册
node.js 学习社区
express nodemailer 出错跪求解决

15802451288

2019-01-17 11:21

var express = require('express');
var router = express.Router();
var nodemailer = require('nodemailer');


/* GET home page. */
router.get('/', function(req, res, next) {

  res.render('mail', { title: 'Express' });
});
router.get('/send', function(req, res, next) {
	var emailName = req.query['email'];
	var mailTransport = nodemailer.createTransport({
		 host:'smtp.qq.com',
		// port:465,
		// host: 'smtp.qq.com',
	    service: 'qq',
	    secure: true,
		// secureConnection:true,
		auth:{
			user:'2713103144@qq.com',
			pass:'mjsxhprbkzj11111'
		}
	});
	var options = {
		from:"2713103144@qq.com",
		to:emailName,
		subject:'这里是subject',
		text:'这里是text',
		html:'<h1>你好,这里是html</h1>'
	};
	console.log(options);
	mailTransport.sendMail(options, function(err, msg){
		if(err){
			console.log(err);
		}else{
			console.log("------------>"+msg);
			res.send("发送成功");
		}
	})
  
});
module.exports = router; 
出现以上图片错误 有人能解决吗

回复 · 2

  • smtp.qq.com 被拒绝了,你从浏览器登陆下邮箱,去设置里把 smtp.qq.com 465 打开,应该是邮箱的安全限制,没有对外开放这个。

    0

  • 这是我服务器运行中的代码

    var nodemailer = require("nodemailer");
    var smtpTransport = require('nodemailer-smtp-transport'); 
    
    var to = "1111111111";
    var html = "22222222";
    var subject = "3333333"; 
    
    var transport = nodemailer.createTransport(smtpTransport({
            host: 'smtp.exmail.qq.com',
            port: 465,
            secure:true,
            auth: {
                user: 'no_reply@xxxxx.com',
                pass: 'xxxxxx'
            }
    }));
    
    var mailOptions = {
            from: 'XX网 <no_reply@xxxxx.com>',
            to: to,
            subject:subject,
            html:html
    }; 
    
    transport.sendMail(mailOptions, function(error, info){
            if(error){
                console.log(error);
            }else{
                console.log(info.response);
            }
    }); 

    0

发表回复

你可以在回复中 @ 其他人