How to change delay time ?
abhikm1991 opened this issue · comments
Hello @abhikm1991
Take a look on 'revolvingInterval', 'maxRevolvingDelay' and 'minRevolvingDelay' in readme docs on the front page.
Hope that helps, let me know :)
Hello @dr-dimitru
Can you show in the Node Coding ?
I tried like,
MongoClient.connect(config.development.MONGODB_URI, (error, client) => {
const db = client.db(dbName);
**const RI = client.revolvingInterval(100);**
const mailQueue = new MailTime({
RI,
db, // MongoDB
type: 'server',
strategy: 'balancer', // Transports will be used in round robin chain
transports,
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 + '>';
},
concatEmails: true, // Concatenate emails to the same addressee
concatDelimiter: '<h1>{{{subject}}}</h1>', // Start each concatenated email with it's own subject
template: MailTime.Template // Use default template
});
emailarray.forEach(email => {
mailQueue.sendMail({
to: email,
subject: 'You\'ve got an email!',
text: 'Plain text message',
html: '<h1>HTML</h1><p>Styled message</p>'
});
});
});
return res.status(200).json({
success: true,
message: `email sent`
});
Looks good.
Just add 'revolvingInterval', 'maxRevolvingDelay', or 'minRevolvingDelay' to adjust timings as in readme docs on the front page.
@dr-dimitru
I tried with
MongoClient.connect(config.development.MONGODB_URI, (error, client) => {
const db = client.db(dbName);
const RI = client.revolvingInterval(100);
const mailQueue = new MailTime({
RI,
...............
this is Giving Error for me. Can you elaborate on your answer in my coding Plz?
Pass it as options to MailTime Constructor
This is my coding. Works Well. but unfortunately, I didn't get you. Can you teach me once ?
const mongoose = require('mongoose');
const MailTime = require('mail-time');
const MongoClient = require('mongodb').MongoClient;
const config = require('../config/config.json');
const dbName = 'NodeLearning';
exports.emailQueue = (req, res, next) => {
try {
if (!req.body.emailarray) {
res.status(400).json({
success: false,
errors: 'Plese send email ids in emailarray'
});
}
let emailarray = req.body.emailarray
const transports = [];
const nodemailer = require('nodemailer');
const directTransport = require('nodemailer-direct-transport');
const directTransportOpts = {
pool: false,
direct: true,
name: 'example',
from: 'noreply@example.com',
};
transports.push(nodemailer.createTransport(directTransport(directTransportOpts)));
transports[0].options = directTransportOpts;
transports.push(nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
from: 'noreply@example.com',
auth: {
user: 'noreply@example.com',
pass: '12345'
},
}));
MongoClient.connect(config.development.MONGODB_URI, (error, client) => {
const db = client.db(dbName);
const mailQueue = new MailTime({
db, // MongoDB
type: 'server',
strategy: 'balancer', // Transports will be used in round robin chain
transports,
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 + '>';
},
concatEmails: true, // Concatenate emails to the same addressee
concatDelimiter: '<h1>{{{subject}}}</h1>', // Start each concatenated email with it's own subject
template: MailTime.Template // Use default template
});
emailarray.forEach(email => {
mailQueue.sendMail({
to: email,
subject: 'You\'ve got an email!',
text: 'Plain text message',
html: '<h1>HTML</h1><p>Styled message</p>'
});
});
});
return res.status(200).json({
success: true,
message: `email sent`
});
} catch (err) {
next(err);
}
}
@abhikm1991 see updated answer below
const mailQueue = new MailTime({
db, // MongoDB
type: 'server',
strategy: 'balancer', // Transports will be used in round robin chain
transports,
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 + '>';
},
concatEmails: true, // Concatenate emails to the same addressee
concatDelimiter: '<h1>{{{subject}}}</h1>', // Start each concatenated email with it's own subject
template: MailTime.Template // Use default template,
revolvingInterval: 100 // <--- CUSTOM OPTIONS GOES HERE
});
@dr-dimitru Thank You So much..Its Working Good
@abhikm1991 sorry for delay with code example was afk, editing code from mobile not easy :/
I'm glad this was solved quickly.
Please support this project with:
- Become a sponsor on GitHub and GitHub would double your every contribution in next 12 months!;
- Support via PayPal;
- Star this package on GitHub;
- Like at Facebook;
- Follow on Twitter;
- Check and star our other open source projects on GitHub.