I am having problem getting my nodejs nodemailer to work. I don't know exactly where I made a mistake because I followed the example on the nodemail github page. As mailserver interface I use mailcow. I tried the default ports from Mailcow here, also with secureConnection false but it made no difference.
My Code:
var usermail = "test@mydomain.com"
var transp = mail.createTransport("SMTP",{
host: "mail.mydomain.com",
port: 587,
secureConnection: true,
auth: {
user: process.env.email,
pass: process.env.passwd
}
})
transp.sendMail({
to: usermail,
subject: "test",
text: "test"
},
function(err,response){
if(err){
console.log(err);
}
console.log(response);
});
My Errorcode:
0|app | TypeError: Cannot create property 'mailer' on string 'SMTP'
0|app | at new Mail (/home/node_modules/nodemailer/lib/mailer/index.js:45:33)
0|app | at Object.module.exports.createTransport (/home/node_modules/nodemailer/lib/nodemailer.js:53:14)
0|app | at /home/routes/system.js:876:35
0|app | at processTicksAndRejections (internal/process/task_queues.js:93:5)
Would be great if someone helps me there times what exactly I did wrong there.
The error tells you, that it can not handle 'SMTP' as a parameter. According to the Documentation, you do not need to specify "SMTP", because it expects an object with the configuration as the first paramter:
var transp = mail.createTransport({
host: "mail.mydomain.com",
port: 587,
secureConnection: true,
auth: {
user: process.env.email,
pass: process.env.passwd
}
})