meteorexim

Meteor email: Connection not closed


I am sending personalized Email notification to my users with Meteor.methods():

Orders._collection.rawCollection()
      .distinct('user', { day: dayId })
      .then((result) => {
        let mailList = []
        User.find({ _id : { $in : result } }).forEach((user) => {
          mailList.push({ to: user.emails[0].address, room: user.profile.room });
        });
        console.log('setting mail queue...')
        mailList.forEach((user, index) => {
          let delay = 0;
          let time = delay + (index*200);
          console.log('queue set for user '+user.to+" for "+ time/1000 +' seconds')
          Meteor.setTimeout(() => {
            console.log('sending mail to: ' + user.to);
            Email.send({
              to: 'user.to',
              from: "test@example.pl",
              subject: "test ",
              html: template,
            });
          }, time)
        })
      });

This example sends all messages, but if there are more than 10 messages then EXIM returns error that there are more than 10 emails in one SMTP connection, and mails are moved to queue to send after 30 minutes. This happens even with 2.5 minute delays after every mail.

Is there any way to close smtp connection with server after mail is sent? mail url is: smtp://localhost:25.


Solution

  • Email package is based on node4mailer (small modification to nodemailer to run it on Node 4).

    By default, Email sets pool=true for transport options. That means that it will reuse opened connection until amount of sent messages reaches its limit, whereas nodemailer default pool options have maxMessages=100.

    Thus, by modifying your MAIL_URL, you have 2 ways to solve your problem:

    1. Pass 10 as maxMessages for nodemailer transport:

      smtp://localhost:25/?maxMessages=10

    2. Disable pool (that will cause nodemailer to open a new connection for every email):

      smtp://localhost:25/?pool=false

    Useful link: nodemailer documentation: Pooled SMTP