如何在Nodemailer中添加取消订阅功能



在查看了Nodemailer的文档后,我找不到任何关于取消订阅电子邮件的信息。

我正试图为我的网络应用程序创建一个时事通讯,我不想使用Mailchimp或任何其他电子邮件服务,因为它们不是永远免费的。

你对我该怎么做有什么想法吗?

我们将非常感谢您的帮助!

const htmlEmailBody = `generate the HTML Body of the email`
const emailHash = `abc123` // Best way is to get this from your database. 
await transporter.sendMail({
from: {
name: 'Your Name',
address: 'abc@example.com',
},
to: userEmailId,
replyTo: 'abc@example.com',
subject: `Hello World`,
html: htmlEmailBody,
list: {
unsubscribe: {
url: `https://example.com/unsubscribe/${emailHash}`,
comment: 'Unsubscribe from Daily Updates',
},
}
});

我的另一个js文件初始化了transport。为了完整起见,请分享此信息。

import { createTransport } from 'nodemailer';
import * as aws from "@aws-sdk/client-ses";
// Create SES instance
const sesClient = new aws.SES({
region: 'ap-south-2',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
export const transporter = createTransport({
SES: {
ses: sesClient,
aws,
},
// https://nodemailer.com/transports/ses/#example-2
sendingRate: 12, // max 12 emails per second
});

最新更新