Home > front end >  How to send a email using a random email and password combination using SMTP and nodemailer
How to send a email using a random email and password combination using SMTP and nodemailer

Time:10-14

So far, I have the following code:

var nodemailer = require('nodemailer');
const finalemail = [`${process.env.email1}`, `${process.env.email2}`, `${process.env.email3}`]
const finalpass = [`${process.env.pass1}`, `${process.env.pass2}`, `${process.env.pass}`]
for (let i = 1; i < 5; i  ) {
  console.log(`${finalemail}`);
  console.log(`${finalpass}`);
  var transporter = nodemailer.createTransport({
    service: 'smtp.mail.com',
    auth: {
      user: `${finalemail}`,
      pass: `${finalpass}`
    }
  });
  var mailOptions = {
    from: `${finalemail}`,
    to: `[email protected]`,
    subject: `send ${i}`,
    text: `${i} emails sent`
  };


  transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
      console.log(error);
    } else {
      console.log('Email sent: '   info.response);
    }
  });
}

I do not know how to make it randomized, and I do not know how to make the email go with the correct password.

CodePudding user response:

Just use Math.random

let ex = Math.floor(Math.random() * finalemail.length)
console.log(`Email: ${finalemail[ex]}\nPass: ${finalpass[ex]}`);

CodePudding user response:

let n = Math.floor(Math.random() * 3) 1

CodePudding user response:

I corrected your error as far as I have tested, I used replit's environment for testing by the way

var nodemailer = require('nodemailer');
const finalemail = [`${process.env.email1}`, `${process.env.email2}`, `${process.env.email3}`]
const finalpass = [ `${process.env.pass1}`, `${process.env.pass2}`, `${process.env.pass3}`]
var finmail = Math.floor(Math.random() * finalemail.length)
console.log(`${finalemail[finmail]}\n${finalpass[finmail]}`);
for (let i = 1; i < 5; i  ) {
  console.log(`${finalemail}`);
  console.log(`${finalpass}`);
var transporter = nodemailer.createTransport({
            service: 'gmail',
            auth: {
              user: `${finalemail[finmail]}`,
              pass: `${finalpass[finmail]}`
            }
          });
          var mailOptions = {
            from: `${finalemail[finmail]}`,
            to: `${to}`,
            subject: `${subject}`,
            text: `${text}`
          };


  transporter.sendMail(mailOptions, function(error, info) {
    if (error) {
      console.log(error);
    } else {
      console.log(`${i}`   'Email'   'sent: '   info.response);
    }
  });
}

This should answer your question.

CodePudding user response:

const rndInt = Math.floor(Math.random() * 6)   1
console.log(rndInt)

From: Generate random number between two numbers in JavaScript

  • Related