ezGmail

package module
v0.0.0-...-663fe4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2016 License: GPL-3.0 Imports: 15 Imported by: 0

README

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()))
				}
			}
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GmailAttachment

type GmailAttachment struct {
	// contains filtered or unexported fields
}

func (*GmailAttachment) GetAttachmentId

func (ga *GmailAttachment) GetAttachmentId() string

func (*GmailAttachment) GetData

func (ga *GmailAttachment) GetData() []byte

func (*GmailAttachment) GetFilename

func (ga *GmailAttachment) GetFilename() string

func (*GmailAttachment) GetMessageId

func (ga *GmailAttachment) GetMessageId() string

func (*GmailAttachment) GetMimeType

func (ga *GmailAttachment) GetMimeType() string

func (*GmailAttachment) GetSize

func (ga *GmailAttachment) GetSize() int64

func (*GmailAttachment) IsDownloaded

func (ga *GmailAttachment) IsDownloaded() bool

type GmailMessage

type GmailMessage struct {
	// contains filtered or unexported fields
}

func (*GmailMessage) GetAttachments

func (gm *GmailMessage) GetAttachments() []*GmailAttachment

func (*GmailMessage) GetBodyHtml

func (gm *GmailMessage) GetBodyHtml() []byte

func (*GmailMessage) GetBodyText

func (gm *GmailMessage) GetBodyText() []byte

func (*GmailMessage) GetMessageId

func (gm *GmailMessage) GetMessageId() string

func (*GmailMessage) GetRawMessage

func (gm *GmailMessage) GetRawMessage() *gmail.Message

func (*GmailMessage) GetSubject

func (gm *GmailMessage) GetSubject() string

func (*GmailMessage) HasAttachments

func (gm *GmailMessage) HasAttachments() bool

func (*GmailMessage) HasBodyHtml

func (gm *GmailMessage) HasBodyHtml() bool

func (*GmailMessage) HasBodyText

func (gm *GmailMessage) HasBodyText() bool

func (*GmailMessage) HasSubject

func (gm *GmailMessage) HasSubject() bool

type GmailService

type GmailService struct {
	// contains filtered or unexported fields
}

func (*GmailService) Filename

func (gs *GmailService) Filename(fname string) *GmailService

func (*GmailService) From

func (gs *GmailService) From(from string) *GmailService

func (*GmailService) GetListOnly

func (gs *GmailService) GetListOnly() *gmail.ListMessagesResponse

func (*GmailService) GetMessages

func (gs *GmailService) GetMessages() []*GmailMessage

func (*GmailService) GetMessagesRaw

func (gs *GmailService) GetMessagesRaw() []*gmail.Message

func (*GmailService) HasAttachment

func (gs *GmailService) HasAttachment(hasatt bool) *GmailService

func (*GmailService) InAnywhere

func (gs *GmailService) InAnywhere() *GmailService

func (*GmailService) InInbox

func (gs *GmailService) InInbox() *GmailService

func (*GmailService) InSent

func (gs *GmailService) InSent() *GmailService

func (*GmailService) InSpam

func (gs *GmailService) InSpam() *GmailService

func (*GmailService) InTrash

func (gs *GmailService) InTrash() *GmailService

func (*GmailService) InitSrv

func (gs *GmailService) InitSrv()

func (*GmailService) LargerThan

func (gs *GmailService) LargerThan(larger string) *GmailService

func (*GmailService) Match

func (gs *GmailService) Match(match string) *GmailService

func (*GmailService) MatchExact

func (gs *GmailService) MatchExact(matchex string) *GmailService

func (*GmailService) MaxResults

func (gs *GmailService) MaxResults(maxres int64) *GmailService

func (*GmailService) NewerThan

func (gs *GmailService) NewerThan(newer string) *GmailService

func (*GmailService) NewerThanRel

func (gs *GmailService) NewerThanRel(newer string) *GmailService

func (*GmailService) OlderThan

func (gs *GmailService) OlderThan(older string) *GmailService

func (*GmailService) OlderThanRel

func (gs *GmailService) OlderThanRel(older string) *GmailService

func (*GmailService) SmallerThan

func (gs *GmailService) SmallerThan(smaller string) *GmailService

func (*GmailService) Subject

func (gs *GmailService) Subject(subject string) *GmailService

func (*GmailService) To

func (gs *GmailService) To(to string) *GmailService

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL