Skip to content

FIxed Bug - Mail #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 65 additions & 86 deletions functions/mail.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,80 @@
const fs = require("fs");
const csv = require("csv-parser");
const qrcode = require("qrcode");
const nodemailer = require("nodemailer");
const fs = require('fs');
const csv = require('csv-parser');
const qrcode = require('qrcode');
const nodemailer = require('nodemailer');
const Jimp = require("jimp");

const csvFilePath = "./demo.csv";
const outputDir = "./qrcodes";

const csvFilePath = './demo.csv';
const outputDir = './qrcodes';

if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
fs.mkdirSync(outputDir);
}

const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
pool: true,
auth: {
user: "iedcmec@mec.ac.in",
pass: "pass",
},
service: 'gmail',
host: "smtp.gmail.com",
port: 587,
auth: {
user: '',
pass: ''
}
});

let counter = 0;
const emailText = (name) => `Dear ${name},

We hope you are excited about Technohack!
As we approach the hackathon, we want to ensure that the registration process is smooth and easy for everyone.
Please take note of the following instructions regarding registration:

- You will receive a unique QR code as an attachment to this email.
- Please report to the registration desk with your QR code.
- Show your QR code at the counter.
- Our volunteers will scan your QR code and you will receive a name tag with a new QR code pasted on it.
- Please stick or keep your name tag safely throughout the hackathon duration.
- For dinner, snacks, breakfast, and lunch, please show your QR code at the counters.
- If you have any doubts or questions, our voluntees will be happy to assist you.

We hope this information makes the registration process easier for you.
If you have any further questions or concerns, please feel free to reach out to us.
const rows = [];
fs.createReadStream(csvFilePath)
.pipe(csv())
.on('data', (row) => {
rows.push(row);
})
.on('end', async () => {
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const id = row.id;
const email = row.email;
const name = row.name;
const qrCodeData = id;
const qrCodePath = `${outputDir}/${id}.png`;

Best regards,
try {
await qrcode.toFile(qrCodePath, qrCodeData, {
color: {
dark: '#000000',
light: '#FFFFFF',
},
scale: 11,
margin: 2
});

The Technohack Team`;
const qrImage = await Jimp.read(qrCodePath);
const font = await Jimp.loadFont(Jimp.FONT_SANS_16_BLACK);
qrImage.print(font, 130, qrImage.bitmap.height - 20, id);
await qrImage.writeAsync(qrCodePath);

const main = () => {
fs.createReadStream(csvFilePath)
.pipe(csv())
.on("data", async (row) => {
const id = row.id;
const email = row.email;
const name = row.name;
const qrCodeData = id;
const qrCodePath = `${outputDir}/${id}.png`;
try {
await qrcode.toFile(qrCodePath, qrCodeData, {
color: {
dark: "#000000",
light: "#FFFFFF",
},
scale: 11,
margin: 2,
});
const mailOptions = {
from: 'nazimfilzer@gmail.com',
to: email,
subject: 'Welcome to TECHNOO',
text: `SUPPP ${name}!!`,
attachments: [{
filename: `${id}.png`,
path: qrCodePath
}]
};

const qrImage = await Jimp.read(qrCodePath);
const font = await Jimp.loadFont(Jimp.FONT_SANS_16_BLACK);
qrImage.print(font, 130, qrImage.bitmap.height - 20, id);
await qrImage.writeAsync(qrCodePath);
const mailOptions = {
from: "iedcmec@mec.ac.in",
to: email,
subject: "Technohack 2023 - Registration Details",
text: emailText(name),
attachments: [
{
filename: `${id}.png`,
path: qrCodePath,
},
],
};
await transporter.sendMail(mailOptions);
console.log(`Sent QR code for id ${id} to ${email}`);

// if (counter++ % 1 === 0) {
// console.log("Pausing for 15 seconds...");
// await new Promise((resolve) => setTimeout(resolve, 15000));
// console.log("Resuming...");
// }
await transporter.sendMail(mailOptions);
console.log(`Sent QR code for id ${id} to ${email}`);
} catch (error) {
console.error(
`Failed to send QR code for id ${id} to ${email}: ${error}`
);
}
})
.on("end", () => {
console.log("Done generating and sending QR codes");
});
};
if (i % 2 === 1) {
console.log('Pausing for 10 seconds...');
await new Promise(resolve => setTimeout(resolve, 10000));
console.log('Resuming...');
}
} catch (error) {
console.error(`Failed to send QR code for id ${id} to ${email}: ${error}`);
}
}

main();
console.log('Done generating and sending QR codes');
});