veliovgroup / mail-time

📮 Email queue extending NodeMailer with multi SMTP transports and horizontally scaled applications support

Home Page:https://www.npmjs.com/package/mail-time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

from address is not dynamic

opened this issue · comments

Hi dr-dimitru,
I am trying to implement dynamic from address, as all my applications are using the same API with different sender address. I am successful in changing the from address according to each valid from request.

But I am facing one issue here. i.e. If emailOne has invalid sender address, it results in infinite retrying of the mail. But when an different request, lets say emailTwo comes with valid from address, now both the mails are sent using the valid from address[emailTwo's from address]

You can see the code below:
I am creating the transport

var from;
var MailQueue;
//......
//......

MongoClient.connect(MONGO_URL, {
}, (error, client) => {
   const db = client.db("mail");
   MailQueue = new MailTime({
    db,
    type: 'server',
    strategy: 'balancer',
    transports,
    interval: 30
    debug:true,
    from(){
      return from;
    },
    concatEmails: false, 
    template: MailTime.Template 
  });
});
....
....
....
....


app.post('/mail/sendmail', function(req, res){
.....
from = req.body.foo;
....
var sendMailObject = {
to:"xxx",
.....
....};
// Adding to mail-time
MailQueue.sendMail(sendMailObject, function(error, info) {

} );
..
..
});

I am not sure if it is an issue.

Hello @iamsathees ,

  1. What type of topology are you using?
    • One server - many clients
    • Many servers - many clients
  2. How do you set from field? From code sample you've provided I see it's set as variable on server-level.
  3. Do you set from field when calling createTransport?
  4. Have you tried to use from field function as in our example section?:
  const mailQueue = new MailTime({
    // ...
    from(transport) {
      // To pass spam-filters `from` field should be correctly set
      // for each transport, check `transport` object for more options
      return '"Awesome App" <' + transport._options.from + '>';
    },
    // ...
  });

Needs to be mentioned what "sender email" is persistent per each created NodeMailer's transport. You could change "from" fields dynamically, but it might not and should not work. You should create seperate transport per each "sender email" address.

Let me know wdyt.

Hey @iamsathees ,

Any news on your end? Have you solved this issue?

Closed due to silence at issue owner end.
Feel free to reopen it in case if the issue still persists on your end.

commented

@dr-dimitru maybe need create multiple MailTime server instances. per each instance use persistent NodeMailer's transport, is right?

@fangjj no, MailTime constructor accepts multiple transports as array.
As mentioned in my comment above, pass from() option as a Function to dynamically generate from value