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
| function getAuth(auth){ | |
| var Check = require('./Check'); | |
| var obj = new Check(auth); | |
| obj.checkForMediumMail(); | |
| } |
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
| //getMail function retrieves the mail body and parses it for useful content. | |
| //In our case it will parse for all the links in the mail. | |
| getMail(msgId){ | |
| //This api call will fetch the mailbody. | |
| this.gmail.users.messages.get({ | |
| 'userId': this.me, | |
| 'id': msgId | |
| }, (err, res) => { | |
| if(!err){ |
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
| //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){ |
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
| 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 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
| /* | |
| 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 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
| 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 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
| //Deletes the draft. | |
| deleteDraft(id){ | |
| this.attachment.gmail.users.drafts.delete({ | |
| id: id, | |
| userId: this.me | |
| }); | |
| } | |
| //Lists all drafts. | |
| listAllDrafts(){ |
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
| //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 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
| 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 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
| 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; |