Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mail messages sent from nodemailer are not showing in user mail sent box

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);
    });
like image 227
Sunil Yadav Avatar asked Jan 14 '17 06:01

Sunil Yadav


1 Answers

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:

  1. 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).

  2. 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.

like image 175
0x530302 Avatar answered Oct 08 '22 18:10

0x530302