让我们说,我想通过[email protected]发送电子邮件到收件人@ xyz.com。
[当[email protected]收到电子邮件时,他应该看到收件人@ xyz.com和bcc中的[email protected]。
但是当[email protected]收到电子邮件时,他看不到收件人。
我尝试使用邮件编辑器(而不是传输工具)创建和发送电子邮件,但无法正常工作。
我也尝试了抄送,但抄送无法正常工作。
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: '[email protected]',
to: '[email protected]',
bcc: '[email protected]'
subject: 'Sample Mail',
html: text
}
const result = await transporter.sendMail(mailData);
console.log('Mail Sent! \t ID: ' + result.messageId);
请参见envelope
SMTP信封通常是从邮件对象中的抄送,到,抄送和密件抄送字段自动生成的,但是如果出于某些原因要自己指定(自定义信封通常用于VERP地址),则可以使用该信封消息对象中的属性。
let message = {
...,
from: '[email protected]', // listed in rfc822 message header
to: '[email protected]', // listed in rfc822 message header
envelope: {
from: 'Daemon <[email protected]>', // used as MAIL FROM: address for SMTP
to: '[email protected], Mailer <[email protected]>' // used as RCPT TO: address for SMTP
}
}
在您的情况下,以下mailData应该起作用:
const mailData = {
from: '[email protected]',
to: '[email protected]',
bcc: '[email protected]'
subject: 'Sample Mail',
html: text,
envelope: {
from: '[email protected]',
to: '[email protected]'
}
}