2013-06-19 70 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併爲您解決這個問題。

相關問題