Let us say I want to send an email to [email protected]
with bcc copy sent to [email protected]
.
When [email protected]
is receiving an email he should see [email protected]
in the To field, and [email protected]
in the bcc field.
But when [email protected]
receives the email, he is not able to see [email protected]
in the To field.
I tried to create and send email using mail composer instead of transports but it is not working as expected.
I also tried cc but cc is not working as expected.
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);
When the email is received, I expect [email protected] to see [email protected] in the To: field.
The default value is 100 which means that once a connection is used to send 100 messages it is removed from the pool and a new connection is created. Set maxConnections to whatever your system can handle.
You need to configure a transporter with your custom domain info (host, port, user and password) You can find this info in the email configuration of your specific hosting provider. Hi there! I get the message 'email sent' and the function finishes with the status 'ok'.
See envelope
SMTP envelope is usually auto generated from from, to, cc and bcc fields in the message object but if for some reason you want to specify it yourself (custom envelopes are usually used for VERP addresses), you can do it with the envelope property in the message object.
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
}
}
In your case following mailData should do the work:
const mailData = {
from: '[email protected]',
to: '[email protected]',
bcc: '[email protected]',
subject: 'Sample Mail',
html: text,
envelope: {
from: '[email protected]',
to: '[email protected]'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With