[英]How to send emails from my server with a mail server and nodejs
我家里有一台帶靜態IP的服務器,我用域名提供自己的網頁,一切正常。
在我的網頁中,您可以通過電子郵件和密碼注冊。 當您注冊名為nodemailer的節點模塊時,從谷歌帳戶發送電子郵件,問題是谷歌帳戶有發送電子郵件的限制。
所以我需要將nodemailer模塊連接到我自己家中的服務器。
我在谷歌搜索,但沒有類似的答案。
如何在nodejs中使用postfix?
或者如何將haraka模塊與nodemailer一起使用
https://github.com/baudehlo/Haraka
所以我重復我的問題,我需要從我的服務器發送一封電子郵件給任何在我的網站上注冊的電子郵件用戶。
例如...
用戶jose@gmail.com在我的網站上注冊
nodemailer配置是......
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);
}
});
}
電子郵件發送正常,但每天都有限制。
所以我需要使用電子郵件服務器發送我的電子郵件沒有限制.... tnx
編輯2
我用apt-get安裝mailutils
現在我試試
mail mymailin@gmail.com
Cc: // press enter
Subject: Welcome
Hello Mail.
// Ctrl+D
這會將電子郵件發送到我的郵箱,並在垃圾郵件中收到從root@mail.mydomain.com發送的電子郵件
所以,postfix工作,但我仍然無法發送電子郵件與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: 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
我再試試
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
就是這樣......這個問題在哪里?
我也必須這樣做,但我在Azure虛擬Ubuntu Linux服務器上運行我的節點服務器。 我想如果你正在運行Ubuntu,那么從你的家庭服務器可以使用相同的步驟。 這是我發現的工作:
我使用本指南安裝了postfix電子郵件服務器:
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;
我解決了這個問題...
我在sasldb2中添加了一些用戶,而且emailjs工作得很好。
首先使用Svbaker教程安裝postfix,但是,
編輯/etc/postfix/sasl/smtpd.conf改為添加以下行:
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: PLAIN LOGIN
thnx所有的幫助,特別是@Svbaker,為您解決這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.