[英]How to send an email in bcc using Nodemailer
假设我想发送一封电子邮件到recipient@xyz.com
bcc@xyz.com
, bcc@xyz.com
密件抄送副本发送到bcc@xyz.com
。
当bcc@xyz.com
收到电子邮件时,他应该在收件人字段中看到recipient@xyz.com
bcc@xyz.com
,在密件抄送字段中看到bcc@xyz.com
。
但是当bcc@xyz.com
收到电子邮件时,他无法在recipient@xyz.com
字段中看到recipient@xyz.com
bcc@xyz.com
。
我尝试使用邮件编辑器而不是传输来创建和发送电子邮件,但它没有按预期工作。
我也试过 cc 但 cc 没有按预期工作。
const nodemailer = require('nodemailer');
const testAccount = await nodemailer.createTestAccount();
const transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
auth: {
user: testAccount.user,
pass: testAccount.pass
},
tls: { rejectUnauthorized: false }
});
const mailData = {
from: 'xyz@xyz.com',
to: 'recipient@xyz.com',
bcc: 'bcc@xyz.com',
subject: 'Sample Mail',
html: text
}
const result = await transporter.sendMail(mailData);
console.log('Mail Sent! \t ID: ' + result.messageId);
收到电子邮件后,我希望bcc@xyz.com在收件人:字段中看到收件人@xyz.com 。
见信封
SMTP 信封通常是从消息对象中的 from、to、cc 和 bcc 字段自动生成的,但如果出于某种原因您想自己指定它(自定义信封通常用于 VERP 地址),您可以使用消息对象。
let message = {
...,
from: 'mailer@nodemailer.com', // listed in rfc822 message header
to: 'daemon@nodemailer.com', // listed in rfc822 message header
envelope: {
from: 'Daemon <deamon@nodemailer.com>', // used as MAIL FROM: address for SMTP
to: 'mailer@nodemailer.com, Mailer <mailer2@nodemailer.com>' // used as RCPT TO: address for SMTP
}
}
在您的情况下,以下 mailData 应该可以完成工作:
const mailData = {
from: 'xyz@xyz.com',
to: 'recipient@xyz.com',
bcc: 'bcc@xyz.com',
subject: 'Sample Mail',
html: text,
envelope: {
from: 'xyz@xyz.com',
to: 'recipient@xyz.com'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.