Skip to content

Instantly share code, notes, and snippets.

View JaiParakh's full-sized avatar
🏠
Working from home

JaiParakh

🏠
Working from home
View GitHub Profile
@JaiParakh
JaiParakh / INSTRUCTIONS.md
Created February 2, 2019 10:02 — forked from InsaneNaman/INSTRUCTIONS.md
GDG Web Dev Day

GDG New Delhi - Web Developers Day

Note: Please complete all the steps mentioned over here before registering for the event:

Installing Dependencies

1- Node.js

const fs = require('fs');
const readline = require('readline');
const {google} = require('googleapis');
// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/gmail.readonly','https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.compose','https://www.googleapis.com/auth/gmail.send'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const {google} = require('googleapis');
const mailComposer = require('nodemailer/lib/mail-composer');
class CreateMail{
constructor(auth, to, sub, body, task, attachmentSrc=[]){
this.me = 'Enter your email id.';
this.task = task;
this.auth = auth;
this.to = to;
makeBody(){
var arr = [];
for(var i=0;i<this.attachment.length;i++){
arr[i] = {
path: this.attachment[i],
encoding: 'base64'
}
}
//Mail Body is created.
//Send the message to specified receiver.
sendMail(encodedMessage){
this.gmail.users.messages.send({
userId: this.me,
resource: {
raw: encodedMessage,
}
}, (err, result) => {
if(err){
return console.log('NODEMAILER - The API returned an error: ' + err);
//Deletes the draft.
deleteDraft(id){
this.attachment.gmail.users.drafts.delete({
id: id,
userId: this.me
});
}
//Lists all drafts.
listAllDrafts(){
const {google} = require('googleapis');
const mailComposer = require('nodemailer/lib/mail-composer');
class CreateMail{
constructor(auth, to, sub, body, task, attachmentSrc){
this.me = 'Enter your email id.';
this.task = task;
this.auth = auth;
this.to = to;
/*
All the index.js code from first article
*/
function getAuth(auth){
var Mail = require('./createMail.js');
var obj = new Mail(auth, "receiver's gmail Id", 'Subject', 'Body', 'mail');
//'mail' is the task, if not passed it will save the message as draft.
//attachmentSrc array is optional.
const {google} = require('googleapis');
var base64 = require('js-base64').Base64;
const cheerio = require('cheerio');
var open = require('open');
var Mailparser = require('mailparser').MailParser;
class Check{
//auth is the constructor parameter.
constructor(auth){
//THis function checks for mails sent by medium.
//We attatch a query parameter to the request body.
checkForMediumMails(){
var query = "from:noreply@medium.com is:unread";
this.gmail.users.messages.list({
userId: this.me,
q: query
}, (err, res) => {
if(!err){