17

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);
    });
isuruAb
  • 2,202
  • 5
  • 26
  • 39
Sunil Yadav
  • 171
  • 1
  • 5
  • Possible duplicate of [Sending email via Node.js using nodemailer is not working](http://stackoverflow.com/questions/26196467/sending-email-via-node-js-using-nodemailer-is-not-working) – Daniel Netto Jan 14 '17 at 12:21
  • 1
    @DanielNetto nope, not a duplicate of your shared link // To OP: I just stumbled upon the same issue. My mails were also send through SMTP and I expected to find sent mails in the webmailer of that account - but nothing there. If you have any new findings, pls share. – Sebastian G. Marinescu May 16 '17 at 19:03
  • @SebastianG.Marinescu I misread the question. Now that you pointed that out, I see what the OP meant. Do you have any filters applied for your account? – Daniel Netto May 18 '17 at 08:42
  • @DanielNetto Thanks, and nope - no filters, nothing. It seems that we expected this in vain and the app should probably save the sent mail separately.. – Sebastian G. Marinescu May 18 '17 at 09:20
  • Also having this issue. Emails sent using the same SMTP account info from Thunderbird show up, but those from Nodemailer do not. Any update on this? – ndmweb Nov 04 '17 at 08:50

1 Answers1

19

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.

0x530302
  • 381
  • 2
  • 6