//PSEUDO-CODE
var currentProxyAddress = 'https://someproxy'
var listOfProxyAddresses = [
'https://someproxy1',
'https://someproxy2',
'https://someproxy3',
'and so on',
]
const changeProxyAfterMessagesSent = 25 //Or whatever number you want
var messagesSentOnCurrentProxy = 0
function getTransporter() {
if (messagesSentOnCurrentProxy >= changeProxyAfterMessagesSent) {
//Make sure whatever function you write here doesn't choose the currently active proxy!
currentProxyAddress = someFunctionToGetARandomProxyFromTheList()
messagesSentOnCurrentProxy = 0
}
return nodemailer.createTransport({
host: 'smtp.example.com',
port: 465,
secure: true,
proxy: currentProxyAddress
});
}
...
//When you want to send a mail:
getTransporter().sendMail(someOptions).then(() => {
//if success,
messagesSentOnCurrentProxy++
})
//Using async await might be a better approach to avoid synchronization issues
//Current code may potentially have an inaccurate messagesSentOnCurrentProxy (but probably not *too* inaccurate)
Thanks. Will look into thisIn theory it shouldn't be too complicated, pending on what exactly you mean by changing IP address. The following should be a semi-functioning example of a way to rotate proxies after a threshold of successful messages are sent. You'll need to bring your own proxies of course, and handle any authentication they may need.
JavaScript://PSEUDO-CODE var currentProxyAddress = 'https://someproxy' var listOfProxyAddresses = [ 'https://someproxy1', 'https://someproxy2', 'https://someproxy3', 'and so on', ] const changeProxyAfterMessagesSent = 25 //Or whatever number you want var messagesSentOnCurrentProxy = 0 function getTransporter() { if (messagesSentOnCurrentProxy >= changeProxyAfterMessagesSent) { //Make sure whatever function you write here doesn't choose the currently active proxy! currentProxyAddress = someFunctionToGetARandomProxyFromTheList() messagesSentOnCurrentProxy = 0 } return nodemailer.createTransport({ host: 'smtp.example.com', port: 465, secure: true, proxy: currentProxyAddress }); } ... //When you want to send a mail: getTransporter().sendMail(someOptions).then(() => { //if success, messagesSentOnCurrentProxy++ }) //Using async await might be a better approach to avoid synchronization issues //Current code may potentially have an inaccurate messagesSentOnCurrentProxy (but probably not *too* inaccurate)