javascript 如何使用邮件服务器和 nodejs 从我的服务器发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17197940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send emails from my server with a mail server and nodejs
提问by andrescabana86
I have a server with static IP in my home, I serve my own web pages with a domain and all works fine.
我的家里有一台带有静态 IP 的服务器,我使用一个域为我自己的网页提供服务,并且一切正常。
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.
在我的网页中,您可以通过电子邮件和密码进行注册。当您注册一个名为 nodemailer 的节点模块时,从谷歌帐户发送电子邮件时,问题是谷歌帐户对发送的电子邮件有限制。
so I need to connect the nodemailer module to a server in my own home.
所以我需要将 nodemailer 模块连接到我家中的服务器。
I search on google but nothing similar has the answer.
我在谷歌上搜索,但没有类似的答案。
how to use postfix with nodejs??
如何在 nodejs 中使用 postfix?
or how to use haraka module with nodemailer
或者如何在 nodemailer 中使用 haraka 模块
https://github.com/baudehlo/Haraka
https://github.com/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
用户 [email protected] 在我的网站上注册
nodemailer configuration is...
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);
}
});
}
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
所以我需要使用电子邮件服务器来无限制地发送我的电子邮件...... tnx
EDIT 2
编辑 2
i install mailutils with apt-get
我用apt-get安装mailutils
and now i try
现在我尝试
mail [email protected]
Cc: // press enter
Subject: Welcome
Hello Mail.
// Ctrl+D
this sends emails to my mailbox and I receive in SPAM an email sent from [email protected]
这将电子邮件发送到我的邮箱,我在垃圾邮件中收到一封从 [email protected] 发送的电子邮件
so, postfix is working, but I still can't send emails with emailjs or nodemailer...
所以,postfix 正在工作,但我仍然无法使用 emailjs 或 nodemailer 发送电子邮件......
when I try to send emails with emails or nodemailer I get this
当我尝试使用电子邮件或 nodemailer 发送电子邮件时,我得到了这个
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
我在 google 中搜索该错误,并且是 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
I 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 root
再用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 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???
就是这样……问题出在哪里???
回答by Svbaker
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:
我也只需要这样做,但我在 Azure 虚拟 Ubuntu Linux 服务器上运行我的节点服务器。我想如果您运行的是 Ubuntu,同样的步骤也可以在您的家庭服务器上运行。这是我发现的工作:
I installed the postfix email server using this guide:
我使用本指南安装了 postfix 电子邮件服务器:
https://help.ubuntu.com/community/Postfix
https://help.ubuntu.com/community/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:
我发现从 node.js 发送外发电子邮件的最简单方法是使用 emailjs:
http://github.com/eleith/emailjs.git
http://github.com/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.
我发现发送的电子邮件通常最终被标记为垃圾邮件。为避免这种情况,您可以前往管理域名的任何地方(我使用 enom),然后配置 SPF 记录以帮助使您的外发电子邮件看起来合法。
Here is my node.js module to send emails using emailjs:
这是我使用 emailjs 发送电子邮件的 node.js 模块:
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;
回答by andrescabana86
i solve de problem with this...
我解决了这个问题...
i add some users in the sasldb2 and the emailjs works pretty well.
我在 sasldb2 中添加了一些用户,emailjs 运行良好。
first of all install the postfix using the Svbaker tutorialbut,
首先使用Svbaker 教程安装 postfix,但是,
edit /etc/postfix/sasl/smtpd.conf adding the following lines instead:
编辑 /etc/postfix/sasl/smtpd.conf 添加以下几行:
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: PLAIN LOGIN
thnx all your help, specially @Svbaker and serve you the solution to this problem.
感谢您的所有帮助,特别是@Svbaker,并为您提供解决此问题的方法。