Git Product home page Git Product logo

ezgmail's Introduction

ezGmail

ezGmail is a golang wrapper for the gmail API. It is designed to be an easy way to access received email and process them. Easy refers to predefined filters to narrow down which mails will be selected and easy way to extract body and attachments from the nested structure of emails.

The package is based on the Gmail API, and so uses OAuth 2.0 authentication, and the code is based on sample program provided in Gmail API's Go quickstart guide.

We wrote this package to enable us to quickly write scripts that process specific messages automatically. It enables us to setup an automated workflow where we are unable to avoid email as the communication medium.

To download ezGmail and its dependencies, use the command: go get github.com/LDCS/ezGmail

To allow ezGmail to access a gmail account, the Gmail API needs to be enabled for that account, and the client_secret.json file needs to be in the same directory as the main program.

Follow step 1 in https://developers.google.com/gmail/api/quickstart/go to enable the Gmail API and download the client_secret.json file.

Here's a sample program that uses some of the functionality provided by the package:

package main

import (
        "fmt"
	"github.com/LDCS/ezGmail"
)

func main() {
	var gs ezGmail.GmailService
	// InitSrv() uses client_secret.json to try to get a OAuth 2.0 token,  , if not present already.
	gs.InitSrv()

	// We compose a search statement with filter functions
	gs.InInbox().MaxResults(1).NewerThanRel("10d").Match("-address").HasAttachment(true)

	// GetMessages() tries to execute the search statement and get a list of messages
	for _, ii := range(gs.GetMessages()) {
		fmt.Println("\nTrying Subject")
		if ii.HasSubject() { fmt.Println(ii.GetSubject()) }
		fmt.Println("\nTrying BodyText")
		if ii.HasBodyText()    { fmt.Println(string(ii.GetBodyText())) }
		fmt.Println("\nTrying BodyHtml")
		if ii.HasBodyHtml()    { fmt.Println(string(ii.GetBodyHtml())) }
		fmt.Println("\nTrying Attachments")
		if ii.HasAttachments() {
			for _, jj := range(ii.GetAttachments()) {
				fmt.Println("\nMimeType")
				fmt.Println(jj.GetMimeType())
				if jj.GetFilename() == "readme.txt" {
					fmt.Println(string(jj.GetData()))
				}
			}
		}
	}
}

ezgmail's People

Contributors

milkhaa avatar shsms avatar teamldcs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.