@haatlabs-core/邮件
发送应用程序的电子邮件(签名编码). 应用软件叫做 Mailer; 邮件叶如何是
适配器, a MailTransport,每个供应商一个.
const mailer = mailerFromConfig(config.mail); // SMTP from config-core's MailConfig, or not configured
if (mailer.configured) await mailer.send({ to, subject, text });
createMailer({ from, transport: smtpTransport({ host, port, secure, user, password }) });
createMailer({ from, transport: memoryTransport() }); // tests: keeps what it is sent
添加提供者 (一个带有密钥的电子邮件 API): 写一个适配器,然后在
mailerFromConfig 从配置。 应用程序里没有什么变化.
export function exampleApiTransport(options: { apiKey: string }): MailTransport {
return {
name: 'example-api',
send: async ({ from, to, subject, text }) => {
const response = await fetch('https://api.example.com/send', {
method: 'POST',
headers: { authorization: `Bearer ${options.apiKey}`, 'content-type': 'application/json' },
body: JSON.stringify({ from, to, subject, text }),
});
if (!response.ok) throw new Error(`example-api refused the email (HTTP ${response.status})`);
},
};
}
适配器在提供者拒绝或无法联系时投出, 并且永远不记录它的内容
发送:登录码和密码一样好. 没有供应商, configured 错误
财务报告和审定财务报表 send 拒绝使用 EMAIL_ERROR。 。 。 .
安装
pnpm add @haatlabs-core/mailer