gpt4 book ai didi

node.js - Nodemailer 无需 smtp 传输即可发送电子邮件

转载 作者:IT老高 更新时间:2023-10-28 22:59:26 32 4
gpt4 key购买 nike

我正在尝试通过没有 SMTP 传输的 nodemailer 发送电子邮件。所以我做到了:

var mail = require("nodemailer").mail;

mail({
from: "Fred Foo ✔ <foo@blurdybloop.com>", // sender address
to: "******@gmail.com", // list of receivers
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
});

但是当我运行时,我明白了:

> node sendmail.js
Queued message #1 from foo@blurdybloop.com, to vinz243@gmail.com
Retrieved message #1 from the queue, reolving gmail.com
gmail.com resolved to gmail-smtp-in.l.google.com for #1
Connecting to gmail-smtp-in.l.google.com:25 for message #1
Failed processing message #1
Message #1 requeued for 15 minutes
Closing connection to the server

Error: read ECONNRESET
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)

我在 Windows 7 32 上。

编辑 这似乎是一个与 Windows 相关的错误,因为它在 linux 上工作

编辑#2

在 git shell 上,如果我输入 telnet smtp.gmail 587 它会在此处被阻止:

220 mx.google.com ESMTP f7...y.24 -gsmtp

最佳答案

从您的示例输出看来,它似乎连接到了错误的端口 25,打开的 gmail smtp 端口是 465 用于 SSL 和其他 587 TLS。

Nodemailer 根据电子邮件域检测到正确的配置,在您的示例中,您没有设置传输器对象,因此它使用配置的默认端口 25。要更改端口,请在选项中指定类型。

这是应该与 gmail 一起使用的小示例:

var nodemailer = require('nodemailer');

// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: 'Gmail',
auth: {
user: "test.nodemailer@gmail.com",
pass: "Nodemailer123"
}
});

console.log('SMTP Configured');

// Message object
var message = {

// sender info
from: 'Sender Name <sender@example.com>',

// Comma separated list of recipients
to: '"Receiver Name" <nodemailer@disposebox.com>',

// Subject of the message
subject: 'Nodemailer is unicode friendly ✔',

// plaintext body
text: 'Hello to myself!',

// HTML body
html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>'
};

console.log('Sending Mail');
transport.sendMail(message, function(error){
if(error){
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');

// if you don't want to use this transport object anymore, uncomment following line
//transport.close(); // close the connection pool
});

关于node.js - Nodemailer 无需 smtp 传输即可发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23016208/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com