最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to send emails from my server with a mail server and nodejs - Stack Overflow

programmeradmin2浏览0评论

I have a server with static IP in my home, I serve my own web pages with a domain and all works fine.

in 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 the sent emails.

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

I search on google but nothing similar has the answer.

how to use postfix with nodejs??

/

or how to use haraka module with nodemailer

so I repeat my question, I need to send an email from my server to any email user that register in my web.

for example...

user [email protected] register in my web

nodemailer configuration is...

exports.newRegistration=function(parametros,callback)
{
    var mailOptions = 
    {
        from: "<[email protected]>",//my email
        to: parametros.useremail,//user email
        subject: 'Wele '+parametros.useremail+'.',
        html:   '<br><b>Hello</b><br>'+ // html 

    };
    var smtpTransport = nodemailer.createTransport("SMTP",
    {
        service: "Gmail",
        secureConnection: true,
        auth:
        {
            user: "[email protected]",
            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 email sends ok, but it has a limit per day.

so I need to use an email server to send my emails with no limit.... tnx

EDIT 2

i install mailutils with apt-get

and now i try

mail [email protected]
Cc: // press enter
Subject: Wele

Hello Mail.

// Ctrl+D

this sends emails to my mailbox and I receive in SPAM an email sent from [email protected]

so, postfix is working, but I still can't send emails with emailjs or nodemailer...

when I try to send emails with emails or nodemailer I get this

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

I search in google that error and is and auth login error, I can't login to the system. so I try with telnet

telnet localhost 25
ehlo localhost
250-mydomain
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: [email protected]
501 5.5.4 Syntax: MAIL FROM:<address>
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
451 4.3.0 <[email protected]>: Temporary lookup failure
data
554 5.5.1 Error: no valid recipients
AUTH LOGIN
503 5.5.1 Error: MAIL transaction in progress

I try again

220 mydomain ESMTP Postfix (Ubuntu)
ehlo localhost
250-mydomain
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 root

220 mydomain ESMTP Postfix (Ubuntu)
ehlo localhost
250-mydomain
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 the 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's it... where is the problem in this???

I have a server with static IP in my home, I serve my own web pages with a domain and all works fine.

in 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 the sent emails.

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

I search on google but nothing similar has the answer.

how to use postfix with nodejs??

http://www.postfix/

or how to use haraka module with nodemailer

https://github./baudehlo/Haraka

so I repeat my question, I need to send an email from my server to any email user that register in my web.

for example...

user [email protected] register in my web

nodemailer configuration is...

exports.newRegistration=function(parametros,callback)
{
    var mailOptions = 
    {
        from: "<[email protected]>",//my email
        to: parametros.useremail,//user email
        subject: 'Wele '+parametros.useremail+'.',
        html:   '<br><b>Hello</b><br>'+ // html 

    };
    var smtpTransport = nodemailer.createTransport("SMTP",
    {
        service: "Gmail",
        secureConnection: true,
        auth:
        {
            user: "[email protected]",
            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 email sends ok, but it has a limit per day.

so I need to use an email server to send my emails with no limit.... tnx

EDIT 2

i install mailutils with apt-get

and now i try

mail [email protected]
Cc: // press enter
Subject: Wele

Hello Mail.

// Ctrl+D

this sends emails to my mailbox and I receive in SPAM an email sent from [email protected]

so, postfix is working, but I still can't send emails with emailjs or nodemailer...

when I try to send emails with emails or nodemailer I get this

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

I search in google that error and is and auth login error, I can't login to the system. so I try with telnet

telnet localhost 25
ehlo localhost
250-mydomain.
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: [email protected]
501 5.5.4 Syntax: MAIL FROM:<address>
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
451 4.3.0 <[email protected]>: Temporary lookup failure
data
554 5.5.1 Error: no valid recipients
AUTH LOGIN
503 5.5.1 Error: MAIL transaction in progress

I try again

220 mydomain. ESMTP Postfix (Ubuntu)
ehlo localhost
250-mydomain.
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 root

220 mydomain. ESMTP Postfix (Ubuntu)
ehlo localhost
250-mydomain.
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 the 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's it... where is the problem in this???

Share Improve this question edited Dec 8, 2016 at 8:18 NIMISHAN 1,2654 gold badges21 silver badges31 bronze badges asked Jun 19, 2013 at 17:51 andrescabana86andrescabana86 1,7888 gold badges31 silver badges56 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

I just had to do this as well, but I am running my node server on an Azure virtual Ubuntu Linux server. I imagine the same steps would work from your home server if you're running Ubuntu. Here is what I found worked:

I installed the postfix email server using this guide:

https://help.ubuntu./munity/Postfix

It looked like a lot of work at first, but it worked for me pretty easily.

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

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

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

Here is my node.js module to send 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;

i solve de problem with this...

article using postfix

i add some users in the sasldb2 and the emailjs works pretty well.

first of all install the postfix 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, specially @Svbaker and serve you the solution to this problem.

发布评论

评论列表(0)

  1. 暂无评论