我使用 Meteor.js 中的内置功能发送注册电子邮件和密码重置电子邮件:
Meteor 使用 NodeMailer 中的 MailComposer 来发送电子邮件,并且这个包似乎支持电子邮件签名。我可以在 Meteor 中配置 DKIM 私钥以便对我的电子邮件进行签名吗?
Meteor-Mailer 支持开箱即用的 DKIM 签名,也支持 SES。
var transport = nodemailer.createTransport("SES", {
AWSAccessKeyID: "AWSACCESSKEY",
AWSSecretKey: "AWS/Secret/key"
});
// all messages sent with *transport* are signed with the following options
transport.useDKIM({
domainName: "example.com",
keySelector: "dkimselector",
privateKey: fs.readFileSync("private_key.pem")
});
transport.sendMail(...);
请注意,Meteor-Mailer可以有多个 STMP 提供商,并且nodemailer还支持 DKIM 签名。
Accounts 包不支持向节点邮件程序提供 DKIM 密钥 - 但是 - 该包使用通用函数 (Accounts.generateOptionsForEmail) 来创建要邮寄的对象,因此可以楔入该包来提供此功能。
import { Accounts } from 'meteor/accounts-base'
//
// Reconfigure Account.base to allow DKIM insertion
const dkim = {
domainName: Meteor.settings.mail.dkim_domain,
keySelector: Meteor.settings.mail.dkim_key,
privateKey: Meteor.settings.mail.dkim_private
}
// Keep a reference to the original "generate" function
Accounts.generateOptionsForEmailPackage = Accounts.generateOptionsForEmail
// Replace the package function with one that adds the DKIM options
Accounts.generateOptionsForEmail = (email, user, url, reason, extra = {}) => {
const emailParams = Accounts.generateOptionsForEmailPackage(email, user, url, reason, extra)
// If DKIM options provided in settings, add them to the object
if (dkim.domainName && dkim.keySelector && dkim.privateKey) {
emailParams.dkim = dkim
}
// Pass the new options back to the accounts function to be sent.
return emailParams
}
仅在服务器端的 Meteor.startup() 期间实现此操作。请小心,这种方法会在运行时修补程序包,如果程序包发生更改,这可能(很容易)中断。