const http = require('http');
const fs = require('fs');
const url = require('url');
const nodemailer = require('nodemailer');
// 创建一个HTTP服务器
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
// 如果请求的是根路径,返回表单页面
if (parsedUrl.pathname === '/') {
fs.readFile('form.html', (err, data) => {
if (err) {
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end('Internal Server Error');
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
}
// 如果请求的是提交表单,发送邮件
else if (parsedUrl.pathname === '/sendmail') {
let body = [];
req.on('data', (chunk) => {
body
通过node发送邮箱教程
最新推荐文章于 2024-04-19 02:10:06 发布