This file contains 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
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. |
This file contains 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
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; |
This file contains 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
makeBody(){ | |
var arr = []; | |
for(var i=0;i<this.attachment.length;i++){ | |
arr[i] = { | |
path: this.attachment[i], | |
encoding: 'base64' | |
} | |
} | |
//Mail Body is created. |
This file contains 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
//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); |
This file contains 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
//Deletes the draft. | |
deleteDraft(id){ | |
this.attachment.gmail.users.drafts.delete({ | |
id: id, | |
userId: this.me | |
}); | |
} | |
//Lists all drafts. | |
listAllDrafts(){ |
This file contains 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
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; |
This file contains 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
/* | |
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. |
This file contains 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
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 file contains 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
//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){ |
OlderNewer