Little bug when sending to hotmail addreses
Hi @andris9, I'm testing the mailtrain with several addreses (like gmail, hotmail, etc.) and in the case of hotmail when they firstly reject the emails (that seems a common issue), the response code from their server is "crashing" zone-mta and start to restarting several times...
Apr 17 21:09:24 mailtrain zone-mta[9143]: (Sender/default/9143) 15b7d51a46500073f7.001 REJECTED[undefined] [email protected][[email protected]] [email protected] mx=mx1.hotmail.com (550 SC-001 (COL004-MC5F37) Unfortunately, messages from 62.210.147.102 weren't sent. Please contact your Internet service provider since part of their network is on our block list. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors.)
Apr 17 21:09:24 mailtrain zone-mta[9130]: (Process) Uncaught exception
Apr 17 21:09:24 mailtrain zone-mta[9130]: (Process) TypeError: Cannot read property 'toString' of undefined#012 at Object.keys.map.key (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:83:50)#012 at Array.map (native)#012 at fetch (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:82:61)#012 at module.exports (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:13:12)#012 at Immediate.notifyBounce (/opt/zone-mta/plugins/core/http-bounce.js:31:26)#012 at runCallback (timers.js:666:20)#012 at tryOnImmediate (timers.js:639:5)#012 at processImmediate [as _immediateCallback] (timers.js:611:5)#012 TypeError: Cannot read property 'toString' of undefined#012 at Object.keys.map.key (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:83:50)#012 at Array.map (native)#012 at fetch (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:82:61)#012 at module.exports (/opt/zone-mta/node_modules/nodemailer-fetch/lib/fetch.js:13:12)#012 at Immediate.notifyBounce (/opt/zone-mta/plugins/core/http-bounce.js:31:26)#012 at runCallback (timers.js:666:20)#012 at tryOnImmediate (timers.js:639:5)#012 at processImmediate [as _immediateCallback] (timers.js:611:5)
Apr 17 21:09:24 mailtrain zone-mta[9130]: (Process) Server closing down...
Apr 17 21:09:24 mailtrain zone-mta[9130]: (SMTP/external/9130) Service closed
Apr 17 21:09:24 mailtrain zone-mta[9130]: (API) Service closed
Apr 17 21:09:24 mailtrain zone-mta[9143]: (Sender/default/9143) Connection to Queue server closed unexpectedly
Apr 17 21:09:24 mailtrain zone-mta[9166]: (SMTP/feeder/9166) Connection to Queue server closed unexpectedly
Apr 17 21:09:24 mailtrain zone-mta[9141]: (SMTP/feeder/9141) Connection to Queue server closed unexpectedly
Apr 17 21:09:24 mailtrain zone-mta[9154]: (Sender/bounces/9154) Connection to Queue server closed unexpectedly
After that I submited my server to outlook using this form: https://support.live.com/eform.aspx?productKey=edfsmsbl3&ct=eformts (good to know by the way) and the crashes stopped... (because there wasnt more rejected responses from outlook)
I hope this can help to improve the code...
The same exception occurs when Yahoo responds with this message:
(4.7.0 [IPTS04] Messages from xxx.xxx.xxx.xxx temporarily deferred due to user complaints - 4.16.55.1; see https://help.yahoo.com /kb/postmaster/SLN3434.html)
Seems like there is a problem with the fetched content from the url.
Maybe someone can file a PR and only use toString() on the element if options.body[key] is not null?
See this code block:
node_modules/nodemailer-fetch/lib/fetch.js
62 if (options.body) {
63 if (options.contentType !== false) {
64 headers['Content-Type'] = options.contentType || 'application/x-www-form-urlencoded';
65 }
66
67 if (typeof options.body.pipe === 'function') {
68 // it's a stream
69 headers['Transfer-Encoding'] = 'chunked';
70 body = options.body;
71 body.on('error', err => {
72 if (finished) {
73 return;
74 }
75 finished = true;
76 fetchRes.emit('error', err);
77 });
78 } else {
79 if (options.body instanceof Buffer) {
80 body = options.body;
81 } else if (typeof options.body === 'object') {
82 body = new Buffer(Object.keys(options.body).map(key => {
83 let value = options.body[key].toString().trim();
84 return encodeURIComponent(key) + '=' + encodeURIComponent(value);
85 }).join('&'));
86 } else {
87 body = new Buffer(options.body.toString().trim());
88 }
89
90 headers['Content-Type'] = options.contentType || 'application/x-www-form-urlencoded';
91 headers['Content-Length'] = body.length;
92 }
93 // if method is not provided, use POST instead of GET
94 method = (options.method || '').toString().trim().toUpperCase() || 'POST';
95 }
Maybe we need to spread awareness at nodemailer project? @andris9