Goal
Sending emails with nodemailer.
Problem
Sending an email from the remote server ends up with a 535 error (535 Authentication credentials invalid). I'm not using Gmail!
Description
When i logged in at the server, there i pulled the app from my repository, run npm install
& npm build
, copied the .env
file from my local machine to the remote folder and then start the app with node
or pm2
. When i start the app local it works. On the Ubuntu 18.04 server it doesnt.
I have another app on the server and there it works with the same setup (express
, dotenv
& nodemailer
installed for the backend). The port, i set in the .env
works without problems.
What i have tried until now:
- Delete the whole remote folder and installed new as described above.
- Installed the app on the server on different directorys:
var/www/myapp
andhome/user/myapp
- Stopped the other app on the server
- Disabled the ufw firewall
- Tried another emailaccount
- Changed the password to a simple one to make sure that it isnt a thing of a special sign
Checked the settings of my email provider. There isnt any security setting or something like we can find at Gmail
Instead of using
process.env.MAIL
&process.env.MAIL_PW
i tried it withoutdotenv
and that worked:"myaddress@online.de"
&"mypassword"
. Thats the only thing, that worked until now on this app.
Seems that it is the same problem as described here for instance.
So thats how the function looks like:
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
host: process.env.EMAIL_HOST,
port: 465,
secure: true,
tls: {
ciphers: "SSLv3",
rejectUnauthorized: false
},
auth: {
user: process.env.MAIL,
pass: process.env.MAIL_PW
}
});
const sendMail = mailData => {
return new Promise((resolve, reject) => {
const mailOptions = mailData;
transporter.sendMail(mailOptions, (error, data) => {
if (error) {
reject(error);
console.log(error);
} else {
console.log("Message sent: %s", data.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(data));
resolve(data);
}
});
});
};
module.exports = sendMail;
Thats the .env
file:
EMAIL_HOST=smtp.1und1.de
MAIL=myadress@online.de
MAIL_PW=mypassword
PORT=2000
Thats the nginx conf file for this app:
server {
root /home/neo/ehilfe/client/build;
index index.html index.htm index.nginx-debian.html;
server_name e-hilfe.com www.e-hilfe.com;
proxy_set_header Host $http_host;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://localhost:2000/api/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/e-hilfe.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/e-hilfe.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.e-hilfe.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = e-hilfe.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name e-hilfe.com www.e-hilfe.com;
return 404; # managed by Certbot
Thats the error message, i get:
Error: Invalid login: 535 Authentication credentials invalid
at SMTPConnection._formatError (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at SMTPConnection._actionAUTHComplete (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:1523:34)
at SMTPConnection.<anonymous> (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:550:26)
at SMTPConnection._processResponse (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
at SMTPConnection._onData (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
at TLSSocket.emit (events.js:223:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10) {
code: 'EAUTH',
response: '535 Authentication credentials invalid',
responseCode: 535,
command: 'AUTH PLAIN'
}
Error: Invalid login: 535 Authentication credentials invalid
at SMTPConnection._formatError (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
at SMTPConnection._actionAUTHComplete (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:1523:34)
at SMTPConnection.<anonymous> (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:550:26)
at SMTPConnection._processResponse (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:942:20)
at SMTPConnection._onData (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData (/home/neo/ehilfe/node_modules/nodemailer/lib/smtp-connection/index.js:195:44)
at TLSSocket.emit (events.js:223:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10) {
code: 'EAUTH',
response: '535 Authentication credentials invalid',
responseCode: 535,
command: 'AUTH PLAIN'
}
Maybe anybody has experience with such a issue and can help me?
Finally the link to te repository: https://gitlab.com/leonp5/ehilfe
Thanks in advance :)