【发布时间】:2015-11-27 03:49:42
【问题描述】:
免责声明:我不太擅长电子邮件技术方面。
所以我设置了一个免费的zoho mail 帐户,它基本上只是我的域的邮件服务器。这有点通过 mx 记录转发或其他方式工作,我不完全确定它是如何工作的。
无论如何,重点是:在每个 Outlook 中使用我的帐户时,我可以轻松更改 from 字段。所以我的电子邮件地址foo@bar.com 在大多数电子邮件客户端中显示为Foo from bar.com。
现在我想通过带有 SSL 的 SMTP 从我的 donotreply@bar.com 帐户使用 nodemailer (v1.10.0) 发送一些自动电子邮件。我尝试了在文档/互联网上找到的不同方法。他们都只是抛出了一个模棱两可的堆栈跟踪(见下文)。
一旦我停止尝试更改 from 字段,一切正常(wrong from 字段除外)。由于我不知道发生了什么,所以我请求帮助解决此问题。
我尝试将createTransport() 的第二个参数更改为我想要的字段。没用。
nodemailer.createTransport(auth.mail, {from: auth.mail.auth.user});
到
nodemailer.createTransport(auth.mail, {from: 'Foo from bar.com'});
我试过设置auth.mail.from,但也没有用。我已经尝试通过将第二个参数传递给createTransport() 来设置auth.mail.from。
我的代码
var nodemailer = require('nodemailer');
var auth = { mail: { host: 'smtp.zoho.com', port: 465, secure: true, auth: { user: 'donotreply@bar.com', pass: 'strongpassword' } };
var log = require('./log');
var transporter = nodemailer.createTransport(auth.mail, {from: auth.mail.auth.user});
function sendText(settings,cb) {
transporter.sendMail(settings, function (err, info) {
if (err) {
log.warn('Failed to send an Email', err);
} else {
log.info('Successfully sent email', info);
}
if (cb) {
cb(err, info);
}
});
}
这里是我之前谈到的堆栈跟踪
Message failed
at SMTPConnection._formatError (c:\...\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:388:15)
at SMTPConnection._actionStream (c:\...\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:948:30)
at SMTPConnection.<anonymous> (c:\...\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:579:14)
at SMTPConnection._processResponse (c:\...\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:511:16)
at SMTPConnection._onData (c:\...\node_modules\nodemailer\node_modules\nodemailer-smtp-transport\node_modules\smtp-connection\src\smtp-connection.js:357:10)
at emitOne (events.js:77:13)
at TLSSocket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at TLSSocket.Readable.push (_stream_readable.js:110:10)
at TLSWrap.onread (net.js:523:20)
【问题讨论】:
标签: node.js nodemailer