1.1.2 • Published 2 years ago

os-gmail-handler v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Introduction

This module contains simplified Gmail API commands (search/read/send emails).

Installation

Install via npm:

npm i os-gmail-handler

Allow Gmail API

To allow this repo to run, you have to supply your gmail JSON credentials to the handler.

To do so, follow these steps to open the Gmail API: 1) Go to the Google Cloud Console and open a new project. Search for "Gmail API", enable it 2) In the Google Cloud Console, Click on the drawer at the top left and click API & Services -> Credentials 3) At the top "Create credentials" -> "OAuth client ID" -> "Desktop app" 4) Save the credentials JSON on a secured location on your computer

Usage

  • Require the api handler:
const gmailApi = require("os-gmail-handler")

Then initiate the handler and run it:

function start() {
    gmailApi.init("path/to/your/credentials.json", "path/to/store/your/token.json", onPostLoad)
}

// this callback will run after the API initialization
async function onPostLoad(auth) {

    // use the msgSearcher instance to find new messages from your girlfriends.
    // (change the query to search whatever you like. Be advised that it doesn't work exactly like the search in the Gmail web app. Read more about it here:
    // https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list)
    let msgs = await gmailApi.msgSearcher.searchMessages(auth, "subject:Hey honey", gmailApi.msgSearcher.LABEL_UNREAD)

    // run on all of those messages
    for (let i = 0; i < msgs.length; i++) {
        
        // read them one by one
        let msgRead = await gmailApi.msgReader.readMessage(auth, msgs[i].id)
        
        // get the name of the girlfriend
        let from = gmailApi.msgTools.getFrom(msgRead)
        
        // send a new message to the girlfriend
        await gmailApi.msgSender.sendMessage(auth, from.email, "Whatcha doin tonight?", "haha funny and corny content")
    }
}

And more...

Links -> see more tools

  • os-tools-npm -> This module contains fundamental functions to implement in an npm project
  • os-file-handler-npm -> This module contains fundamental files manipulation functions to implement in an npm project
  • os-file-stream-handler-npm -> This module contains read/write and more advanced operations on files
  • os-xml-handler-npm -> This module will build, read and manipulate an xml file. Other handy stuff is also available, like search for specific nodes

GitHub - osfunappsapps

Licence

ISC

1.1.2

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago