2013-06-19 105 views
3

我在家中有一个静态IP的服务器,我为自己的网页提供了一个域,并且一切正常。如何使用邮件服务器和nodejs从我的服务器发送电子邮件

在我的网页上,您可以通过电子邮件和密码注册。当您注册名为nodemailer的节点模块时,会从Google帐户发送电子邮件,问题在于Google帐户具有已发送电子邮件的限制。

所以我需要将nodemailer模块连接到我自己家中的服务器。

我在谷歌搜索,但没有类似的答案。

如何使用postfix与nodejs?

http://www.postfix.org/

或如何使用haraka模块nodemailer

https://github.com/baudehlo/Haraka

所以我重复我的问题,我需要从我的服务器发送电子邮件至,在我的网站注册的任何电子邮件用户。

例如...

用户[email protected]在我的网站进行注册

nodemailer配置...

exports.newRegistration=function(parametros,callback) 
{ 
    var mailOptions = 
    { 
     from: "<[email protected]>",//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: "[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); 
     } 
    }); 
} 

电子邮件发送OK,但它有一个限制每天。

,所以我需要使用电子邮件服务器发送我的电子邮件没有限制.... TNX

EDIT 2

我安装与mailutils apt-get的

,现在我尝试

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

Hello Mail. 

// Ctrl+D 

此电子邮件发送到我的邮箱,我在垃圾邮件收到一封电子邮件,从[email protected]发送

因此,后缀是工作,但我仍然无法发送带有emailjs或nodemailer电子邮件...

当我尝试发送电子邮件与电子邮件或nodemailer我得到这个

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

我在搜索谷歌的错误,是和auth登录错误,我无法登录到系统。 所以我尽量通过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: [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 

我再试

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 

,并再次以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 

这是日志文件

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 

,就是这样。亲们在哪里在这个咩?

回答

6

我只需要这样做,但我在Azure虚拟Ubuntu Linux服务器上运行我的节点服务器。我想如果你运行的是Ubuntu,你的家用服务器也可以使用同样的步骤。下面是我发现的工作:

我安装使用本指南后缀的电子邮件服务器:

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

它看起来像一个大量的工作在第一,但它的工作对我来说很容易地。

我发现从node.js的发送传出电子邮件的最简单方法是使用emailjs:我发现,经常发送电子邮件最终会被标记为垃圾邮件

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

。为了避免这种情况,您可以到您管理域名的任何地方(我使用enom),然后配置SPF记录以帮助您使发出的电子邮件看起来合法。

这里是我的Node.js模块使用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; 
+0

好吧,我觉得这是即时寻找....我会在这一刻 – andrescabana86

+0

想我有一个错误:{[错误:authorization.failed] 代码:3, 以前: {[错误:对命令'N2Z0ZXJhMzU5YzI4YQ =='错误的响应' 代码:2, smtp:'535 5.7.8错误:认证失败:通用故障\ n'}, smtp:undefined} – andrescabana86

1

我解决这个问题解...

article using postfix

我添加一些用户在sasldb2和emailjs工作得很好。

首先上安装使用Svbaker tutorial但是,

编辑/etc/postfix/sasl/smtpd.conf添加以下行,而不是后缀:

pwcheck_method: auxprop 
auxprop_plugin: sasldb 
mech_list: PLAIN LOGIN 

日Thnx所有的帮助,特别是@ Svbaker并为您解决这个问题。

相关问题