Mah*_*han 6 javascript email mail-server node.js
我花了几天时间使用 node.js 实现我自己的邮件服务器。我使用诸如“smtp-server”之类的模块来创建 smtp 服务器,还使用“smtp-connection”来连接并向其发送邮件。但是我很困惑,因为我不知道如何从我的 smtp 服务器向 google 或 yahoo 等提供商的 smtp 服务器发送邮件。
谁能帮我?
这是我的代码以获取更多信息:
我的 index.js 文件:
var SMTPServer = require('smtp-server').SMTPServer;
var port = 9025;
var serverOptions = {
name: "smtp-interceptor",
onConnect: onConnect,
onAuth: onAuth,
onData: onData
};
var server = new SMTPServer(serverOptions);
server.listen(port, 'localhost', function () {
console.log('SMTP server is listening on port ' + port);
});
function onConnect(session, callback) {
console.log('Connected');
return callback(); // Accept the connection
}
function onData(stream, session, callback) {
stream.pipe(process.stdout); // print message to console
console.log('Session \n', session.envelope);
stream.on('end', callback);
}
function onAuth(auth, session, callback){
if(auth.username !== 'Mahan' || auth.password !== 'Tafreshi') {
return callback(new Error('Invalid username or password'));
}
callback(null, {user: 123}); // where 123 is the user id or similar property
}
Run Code Online (Sandbox Code Playgroud)
还有我的 connection.js 文件:
var SMTPConnection = require('smtp-connection');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var connection = new SMTPConnection({
host: 'localhost',
port: 9025,
secure: false
});
connection.connect(function (){
console.log('Connceted to SMTP server');
var auth = {
user: 'Mahan',
pass: 'Tafreshi'
};
connection.login(auth, function (err) {
if(err)
return console.log('Login Failed \n', err);
console.log('Login Successful');
var envelope = {
from: "testapp@testapplocal.com",
to: "mahantp19@gmail.com"
};
var message = 'Test message1';
connection.send(envelope, message, function (err, info) {
if(err)
return console.log('Error : ' + err);
console.log('Message sent');
console.log('Accepted : ' + info.accepted);
console.log('Rejected : ' + info.rejected);
console.log(info.response);
connection.quit();
console.log('Quit connection');
connection.close();
});
});
});
Run Code Online (Sandbox Code Playgroud)
电子邮件在被大多数邮件提供商接受之前必须通过许多检查。这些检查尝试验证发送消息的服务器是否有权代表发件人发送。
IE:我的服务器可以发送一封电子邮件,说它来自“someone-special@somewhere-important.com”...这并不意味着我在“任何重要的地方”。
虽然您过去可能使用 PHP 或 Exchange Server 等其他技术成功地从 SMTP 服务器发送邮件,但规则已经发生了显着变化。Gmail 今年刚刚开始全面实施。
我认为您当前的问题与节点无关,与大型提供商最近的更改无关。
您想要“充当发件人”的任何域都必须具备这些功能,以便大多数主要提供商接受您的消息。
访问Google MX 记录检查器并输入您要用作发件人的域/子域,它会告诉您失败和通过的所有内容。
我花了几年时间尝试跟上所有的变化,不可避免地,我继续遇到消息被阻止的障碍,直到有人没有收到电子邮件才知道。如果您的发送量较低,您应该能够使用第三方而无需付费。如果您的发送量很大,那么与您将遇到的无尽问题相比,即使您最初开始滚动,他们的服务成本也很便宜。
附言。我与任何电子邮件提供商或发件人没有任何关系。我也付钱给他们。
| 归档时间: |
|
| 查看次数: |
1749 次 |
| 最近记录: |