我有一个服务器与静态IP在我的家里,我服务我自己的网页与一个域和所有工作良好。
在我的网页,你可以通过电子邮件和密码注册。当您注册一个名为nodemailer的节点模块,从google帐户发送电子邮件时,问题是google帐户有一个发送电子邮件的限制。
所以我需要将nodemailer模块连接到我自己家里的服务器上。
我在谷歌上搜索,但没有类似的答案。
如何在NodeJS中使用后缀??
http://www.costfix.org/
或者如何与nodemailer一起使用haraka模块
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发邮件...
当我尝试用emails或nodemailer发送电子邮件时,我会得到以下信息
smtp: '535 5.7.8 Error: authentication failed: generic failure\n'
我在谷歌搜索错误,并且是和身份验证登录错误,我无法登录到系统。所以我尝试使用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;