主要是测试以下mailpit 的一些功能(html check )
环境准备
- docker-compose
version: '3'
services:
mailpit:
image: axllent/mailpit
container_name: mailpit
restart: always
volumes:
- ./data:/data
ports:
- 8025:8025
- 1025:1025
environment:
MP_MAX_MESSAGES: 5000
MP_DATA_FILE: /data/mailpit.db
MP_SMTP_AUTH_ACCEPT_ANY: 1
MP_SMTP_AUTH_ALLOW_INSECURE: 1
nodejs client 发送email
基于了emailjs 库
- app.mjs
import { SMTPClient } from 'emailjs';
const client = new SMTPClient({
user: '[email protected]',
host: '127.0.0.1',
port:1025,
ssl: false,
timeout:10000, // 注意此参数比较重要,否则会有发送提示超时的问题
tls:false,
});
client.smtp.debug(1);
// send the message and get a callback with an error or details of the message that was sent
client.send(
{
text: '<div> this is a demo</dov>',
from: '[email protected]',
to:'[email protected]',
"content-type":'text/html; charset=utf-8',
content:'text/html; charset=utf-8',
subject: 'testing emailjs',
},
(err, message) => {
console.log(err || message);
}
);
- 效果
html check
说明
mailpit 整体使用与MailHog 是类似的,支持官方添加了不少新功能,html check 基于了caniemail 是一个很不错的功能,可以快速的发现邮件内容是否兼容邮件客户端
参考资料
https://www.caniemail.com/
https://github.com/HTeuMeuLeu/caniemail
https://mailpit.axllent.org/docs/install/
https://www.npmjs.com/package/emailjs