我正在尝试使用Nodemailer在node.js中发送邮件,但它显示了一些错误
{ [Error: self signed certificate in certificate chain] code: 'ECONNECTION', command: 'CONN' }
我的node.js代码是
var express = require('express');
var app = express();
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport('smtps://something%40gmail.com:password@smtp.gmail.com');
var mailOptions = {
to: 'stevecameron2016@gmail.com',
subject: 'Hello ?',
text: 'Hello world ??',
html: '<b>Hello world ??</b>'
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
var server = app.listen(8900,function(){
console.log("We have started our server on port 8900");
});
答案 0 :(得分:16)
尝试https://github.com/nodemailer/nodemailer/issues/406
将tls: { rejectUnauthorized: false }
添加到您的传输器构造函数选项
p.s发布您的邮件服务器地址不是一个好主意,如果它是真实的
答案 1 :(得分:3)
要允许通过“不太安全的应用”发送电子邮件,请转到the link并选择“开启”。
(More info关于不太安全的应用)
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var mailAccountUser = '<YOUR_ACCOUNT_USER>'
var mailAccountPassword = '<YOUR_ACCOUNT_PASS>'
var fromEmailAddress = '<FROM_EMAIL>'
var toEmailAddress = 'TO_EMAIL'
var transport = nodemailer.createTransport(smtpTransport({
service: 'gmail',
auth: {
user: mailAccountUser,
pass: mailAccountPassword
}
}))
var mail = {
from: fromEmailAddress,
to: toEmailAddress,
subject: "hello world!",
text: "Hello!",
html: "<b>Hello!</b><p><a href=\"http://www.yahoo.com\">Click Here</a></p>"
}
transport.sendMail(mail, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
transport.close();
});
答案 2 :(得分:0)
我也遇到了这个麻烦,我所做的是下一个代码行:
impl<T: ?Sized> Weak<T> {
pub fn new() -> Weak<T> {
unsafe {
let boxed = Box::into_raw(box RcBox {
strong: Cell::new(0),
weak: Cell::new(1),
value: (),
});
let ptr = if size_of::<*mut ()>() == size_of::<*mut T>() {
let ptr: *mut RcBox<T> = transmute_copy(&boxed);
ptr
} else {
let ptr: *mut RcBox<T> = transmute_copy(&TraitObject {
data: boxed as *mut (),
vtable: null_mut(),
});
ptr
};
Weak { ptr: Shared::new(ptr) }
}
}
}
在创建smpttransport之前
例如,在您的代码中只需输入:
conversationUpdate
答案 3 :(得分:0)
@ user3985565说的是正确的。但是,如果您使用的是gmail,则还需要更改gmail帐户中的某些设置。更具体地说,您需要在Gmail帐户中“允许安全性较低的应用程序”。为此,请按照以下步骤操作:
答案 4 :(得分:0)
对我有用。
process.env.NODE_TLS_REJECT_UNAUTHORIZED =“ 0”;