gmail

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 18 Imported by: 0

README

gmail-go

send email via gmail, written in go // ------ based on github.com/mdigger/gmail and github.com/arbarlow/gomail

Examples

  • see example directory

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyType added in v0.0.6

type BodyType string

BodyType - what type of body to set

const (
	Auto BodyType = "auto"
	HTML BodyType = "html"
	Text BodyType = "text"
)

BodyType values

type GoogleMessage

type GoogleMessage struct {
	Header textproto.MIMEHeader // headers

	AccessToken        string
	WriteHeadersSorted bool
	// contains filtered or unexported fields
}

GoogleMessage describes an email message.

func (*GoogleMessage) Attach

func (m *GoogleMessage) Attach(name string, data []byte, headers *textproto.MIMEHeader, inlineCID string) error

Attach attaches to the message an attachment as a file. Passing an empty content deletes the file with the same name if it was previously added.

func (*GoogleMessage) GetAttachments added in v0.0.9

func (m *GoogleMessage) GetAttachments() map[string]*GooglePart

GetAttachments - returns a list of non-body attachment parts

func (*GoogleMessage) GetBody added in v0.0.8

func (m *GoogleMessage) GetBody(bodyType BodyType) (*textproto.MIMEHeader, []byte)

GetBody returns a previously set body of type bodyType if no body for bodyType has been set, the an empty byte slice is returned

func (*GoogleMessage) Has

func (m *GoogleMessage) Has(name string) bool

Has returns true if a file with that name was in the message as an attachment.

func (*GoogleMessage) Send

func (m *GoogleMessage) Send(client *http.Client) (string, error)

Send sends the message through GMail. Pass in client to over-ride the http.Client used. Otherwise the default will be used Returns the Message-Id header for the sent email

func (*GoogleMessage) SetBody

func (m *GoogleMessage) SetBody(data []byte, headers *textproto.MIMEHeader, bodyType BodyType) error

SetBody sets the contents of the text of the letter.

You can use text or HTML message format (is determined automatically). To guarantee that the format will be specified as HTML, consider wrapping the text with <html> tag. When adding the HTML content, text version, to support legacy mail program will be added automatically. When you try to add as message binary data will return an error. You can pass as a parameter the nil, then the message will be without a text submission. Use bodyType to specify which type of body is being set. Using Auto only allows one body part. To have both an html body and a text body, call twice, once for each kind

func (*GoogleMessage) Token

func (m *GoogleMessage) Token() (*oauth2.Token, error)

Token - implement TokenSource interface

func (*GoogleMessage) WriteTo

func (m *GoogleMessage) WriteTo(w io.Writer) (int64, error)

WriteTo generates and writes the text representation of mail messages.

type GooglePart added in v0.0.9

type GooglePart struct {
	Header textproto.MIMEHeader // headers
	Data   []byte               // content
}

GooglePart describes googlePart email message: the file or message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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