Last active
July 21, 2021 01:17
-
-
Save Pompeu/06fe610ba82ef0b4c82026c8073aa04b to your computer and use it in GitHub Desktop.
send_email.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// comandos | |
// npm init | |
// npm install rxjs | |
// npm install @sendgrid/mail | |
const fs = require("fs"); | |
const { from } = require("rxjs"); | |
const { filter, map } = require("rxjs/operators"); | |
const sgMail = require("@sendgrid/mail"); | |
sgMail.setApiKey('sua chave sandgrid aqui'); | |
const removeBlankLines = (x) => x !== ""; | |
const mailBuild = (email) => { | |
const body = { | |
to: email, | |
from: "[email protected]", | |
subject: "Sandgrid Test", | |
text: "Pompeulimp eu vou te seguir insta relaxa!! @pompeulimp", | |
html: `<strong>Ola vem seguir no insta vem por favor? Sr. ${email}</strong>`, | |
}; | |
return body; | |
}; | |
const sendEmail = (body) => | |
sgMail | |
.send(body) | |
.then((result) => { | |
console.log("Email enviado"); | |
console.log(result); | |
}) | |
.catch((error) => { | |
console.error(error); | |
if (error.response) { | |
console.error(error.response.body); | |
} | |
}); | |
const emaillist = fs.readFileSync("./mail_list.txt", "utf8").split("\n"); | |
from(emaillist) | |
.pipe(filter(removeBlankLines), map(mailBuild)) | |
.subscribe(sendEmail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment