How to send letters from my server using mail server and nodejs

I have a server with a static IP address in my house, I serve my own web pages with a domain, and everything works fine.

on my web pages, you can register by email and password. when you register a node module called nodemailer sends an email from a google account, the problem is that the google account has a limit of sent messages.

so I need to connect the nodemailer module to a server in my own home.

I am searching on google, but nothing of the kind has an answer.

how to use postfix with nodejs ??

http://www.postfix.org/

or how to use the haraka module with nodemailer

https://github.com/baudehlo/Haraka

so I repeat my question, I need to send an email from my server to any email user who has registered on my network.

eg...

user jose@gmail.com register in my network

The nodemailer configuration is ...

exports.newRegistration=function(parametros,callback) { var mailOptions = { from: "< myemailingoogle@gmail.com >",//my email to: parametros.useremail,//user email subject: 'Welcome '+parametros.useremail+'.', html: '<br><b>Hello</b><br>'+ // html }; var smtpTransport = nodemailer.createTransport("SMTP", { service: "Gmail", secureConnection: true, auth: { user: " myemailingoogle@gmail.com ", pass: "7ftera359c28a", }, }); smtpTransport.sendMail(mailOptions, function(err, response) { if(err) { smtpTransport.close(); console.warn(err); return callback(err,null); }else{ smtpTransport.close(); return callback(null,response); } }); } 

the letter is sent normally, but it has a daily limit.

so I need to use a mail server to send my letters without restrictions .... tnx

EDIT 2

I am installing mailutils with apt-get

and now I'm trying

 mail mymailin@gmail.com Cc: // press enter Subject: Welcome Hello Mail. // Ctrl+D 

it sends letters to my mailbox, and I receive in SPAM an email sent from root@mail.mydomain.com

so postfix works, but I still can't send emails using mailjs or nodemailer ...

when i try to send emails using email or nodemailer i get this

 smtp: '535 5.7.8 Error: authentication failed: generic failure\n' 

I search on Google that the error is and the login error, I can not log in. so i try with telnet

 telnet localhost 25 ehlo localhost 250-mydomain.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail to: myuserin@gmail.com 501 5.5.4 Syntax: MAIL FROM:<address> mail from: info@mydomain.com 250 2.1.0 Ok rcpt to: myuserin@gmail.com 451 4.3.0 < myuserin@gmail.com >: Temporary lookup failure data 554 5.5.1 Error: no valid recipients AUTH LOGIN 503 5.5.1 Error: MAIL transaction in progress 

I'll try again

 220 mydomain.com ESMTP Postfix (Ubuntu) ehlo localhost 250-mydomain.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN AUTH LOGIN 334 VXNlcm5hbWU6 UbuntuUser 535 5.7.8 Error: authentication failed: another step is needed in authentication 

and again with the root

 220 mydomain.com ESMTP Postfix (Ubuntu) ehlo localhost 250-mydomain.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN auth login 334 VXNlcm5hbWU6 root 334 UGFzc3dvcmQ6 rootPassword 535 5.7.8 Error: authentication failed: another step is needed in authentication 

this is a log file

 Jun 20 15:50:16 myname postfix/smtpd[12528]: warning: localhost[127.0.0.1]: SASL login authentication failed: another step is needed in authentication 

and that he ... where is the problem ???

+4
source share
2 answers

I needed to do this too, but I'm running my node server on an Azure Virtual Ubuntu Linux virtual server. I assume the same steps will work from your home server if you are using Ubuntu. Here is what I found:

I installed postfix mail server using this guide:

https://help.ubuntu.com/community/Postfix

At first it looked like a lot of work, but it worked pretty easy for me.

I found the easiest way to send outgoing mail from node.js to use emailjs:

http://github.com/eleith/emailjs.git

I found that sent emails often end up being marked as spam. To avoid this, you can go to where you manage your domain name (I use enom) and then set up an SPF record to make your outgoing email address legal.

Here is my node.js module for sending emails using emailjs:

  var email = require("emailjs"); postfixSend = function postfixSend(emailInfo, callback) { var server = email.server.connect({ user: "yourEmailAccountUser", password: "yourPassword", host: "localhost", ssl: false }); server.send({ text: emailInfo.msg, from: emailInfo.from, to: emailInfo.to, subject: emailInfo.subject }, function(err, message) { callback(err); }); } exports.postfixSend = postfixSend; 
+6
source

I solve the problem with this ...

postfix article

I am adding some users to sasldb2 and emailjs works very well.

install postfix first using the svbaker tutorial but

edit / etc / postfix / sasl / smtpd.conf, adding the following lines instead:

 pwcheck_method: auxprop auxprop_plugin: sasldb mech_list: PLAIN LOGIN 

thnx all your help, especially @Svbaker, will serve you as a solution to this problem.

+1
source

Source: https://habr.com/ru/post/1487107/


All Articles