Disclaimer: I am not very good at technical aspects of email.
So, I set up a free zoho mail account , which is basically just a mail server for my domain. This view works through mx record forwarding or something else, I'm not quite sure how it works.
In any case, the fact is that I can easily change the field from the field when using my account for Outlook. Therefore, my email address foo@bar.com displayed as Foo from bar.com in most email clients.
Now I want to send some automatic emails from my donotreply@bar.com account using nodemailer (v1.10.0) via SMTP using SSL. I tried different approaches that I found in the documentation / on the Internet. All of them simply threw an ambiguous stack trace (see below).
As soon as I stop trying to change the from field, everything works fine (except for the wrong field). Since I have no idea what is going on, I ask some to help fix this problem.
I tried changing the second argument to createTransport() to my desired from the field. Does not work.
nodemailer.createTransport(auth.mail, {from: auth.mail.auth.user});
to
nodemailer.createTransport(auth.mail, {from: 'Foo from bar.com'});
I tried setting auth.mail.from , which also did not work. And I tried to set auth.mail.from with passing the second parameter to createTransport() .
My code
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); } }); }
Here is the stack I talked about before
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)