Nodemailer发送电子邮件而无需SMTP传输

编程入门 行业动态 更新时间:2024-10-25 15:35:08
本文介绍了Nodemailer发送电子邮件而无需SMTP传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I am trying to send emails via nodemailer without SMTP transport. So i've done that:

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

但是当我跑步时我会得到:

But when I run I get that :

> node sendmail.js Queued message #1 from foo@blurdybloop, to vinz243@gmail Retrieved message #1 from the queue, reolving gmail gmail resolved to gmail-smtp-in.l.google for #1 Connecting to gmail-smtp-in.l.google: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上。

I am on windows 7 32.

编辑 这似乎是与Windows相关的错误,因为它可以在Linux上运行

EDIT This seems to be a windows related bug for it worked on linux

编辑#2

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

On the git shell, if I enter telnet smtp.gmail 587 it is blocked here:

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

推荐答案

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

From your example output it seems to connecting to wrong port 25, gmail smtp ports which are opened are 465 for SSL and the other 587 TLS.

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

Nodemailer detects the correct configuration based on the email domain, in your example you have not set the transporter object so it uses the default port 25 configured. To change the port specify in options the type.

以下是应该与gmail配合使用的小示例:

Here's the small example that should work with gmail:

var nodemailer = require('nodemailer'); // Create a SMTP transport object var transport = nodemailer.createTransport("SMTP", { service: 'Gmail', auth: { user: "test.nodemailer@gmail", pass: "Nodemailer123" } }); console.log('SMTP Configured'); // Message object var message = { // sender info from: 'Sender Name <sender@example>', // Comma separated list of recipients to: '"Receiver Name" <nodemailer@disposebox>', // 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 });

更多推荐

Nodemailer发送电子邮件而无需SMTP传输

本文发布于:2023-10-13 00:23:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1486285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Nodemailer   SMTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!