我正在使用来自 nodemailer 的
smtp-server
构建一个 SMTP 服务器,我已经正确设置了我的 DNS,遵循 Simon Carr 的这篇文章https://simonjcarr.medium.com/create-an-smtp-server-with- nodejs-5688d8fd882e,虽然端口转发部分我不是很懂
我正在使用 Windows 10 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz 2.81 GHz,
Node.js版本v16.13.1; NPM 版本 9.2.0
// ESM
import fastifyPlugin from 'fastify-plugin'
import chalk from 'chalk'
import { SMTPServer } from 'smtp-server'
import { simpleParser } from 'mailparser'
/**
* @param {FastifyInstance} fastify
* @param {Object} options
*/
async function email_server(fastify, options, done) {
const server = new SMTPServer({
handshakeTimeout: 60000,
closeTimeout: 60000,
socketTimeout: 60000,
sessionTimeout: 60000,
logger: true,
secure: true,
secureConnection: true,
requiresAuth: false,
requestCert: true,
requireTLS: true,
disabledCommands: ["AUTH"],
tls: {
rejectUnauthorized: true,
},
onData(stream, session, callback) {
simpleParser(stream, {}, (err, parsed) => {
if (err)
console.log("Error:", err)
console.log(parsed);
console.log(chalk.redBright("Recieved an email right about now"))
stream.on("end", callback)
})
},
onConnect(session, callback) {
console.log("SMTP connection established.");
callback(null);
},
onClose(session, callback) {
console.log("SMTP connection closed.");
},
});
server.on("error", err => {
console.log("Error %s", err.message);
});
server.listen(25, () => {
console.log(chalk.yellowBright("started smtp server"))
})
fastify.get('/plugin', (request, reply) => {
reply.send({ plugin: 'a plugin registered' })
})
fastify.ready(err => {
if (err) return done(new Error(err))
console.log(chalk.yellow(`Mail server connected successfully`))
})
}
// Wrapping a plugin function with fastify-plugin exposes the decorators
// and hooks, declared inside the plugin to the parent scope.
export default fastifyPlugin(email_server)
我的 MX 记录指向我的 windows WIFI 2 ipv4 地址 我正在关注这篇中篇文章https://simonjcarr.medium.com/create-an-smtp-server-with-nodejs-5688d8fd882e。 谢谢。