I am sending messages from my domain account but they are not showing in user(from options of nodemailer) sent box.But when sending messages from gmail service messages are showing in sent box of user.Am I missing something in below code?
var transport = nodemailer.createTransport({
host: "xxxx.domain.com",
auth: {
user: 'xyx',
pass: '123'
}
});
transport.sendMail(options, function (err, info) {
if (err) {
console.log(err)
}
console.log(info);
});
When you send a mail using a regular mail client, such as Thunderbird, it will send the mail to your SMTP server, which then relays the message to the receiving mail server (also via SMTP). The copy in your sent folder, however, is additionally saved on your mail server via IMAP. So your mail is actually send twice, once to the receivers mail server, and a copy is "send" to your own mail server.
When using nodemailer you only provide the credentials for your SMTP server, so the mail is only send without storing a copy in your sent directory. So this is basically working as intended.
I can think of two ways to save a copy of the mail in the sent directory:
Use an additional library, such as node-imap
to imitate the behavior of a regular mail client and manually save a copy of the mail (e.g., node-imap
has an append
method to save new mails).
Add your own mail address as BCC to all outgoing mails and use some type of server side filtering to automatically move them to the sent folder. This is computationally less expensive for your application, but has the additional filtering requirement for the mail server.
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