gmail

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCredentials means no credentials are provided to initialize the Gmail service.
	ErrNoCredentials = errors.New("no credentials provided")
)

Functions

func Factory added in v0.8.0

func Factory(_ context.Context, cfg map[string]interface{}) (postdog.Transport, error)

Factory accepts configuration as a map[string]interface{} and instantiates the Gmail transport from it.

Example configuration:

cfg := map[string]interface{}{
  "credentials": "/path/to/credentials.json",
  "scopes": []string{gmail.MailGoogleComScope},
  "jwtSubject": "bob@example.com",
}

func Transport added in v0.8.0

func Transport(opts ...Option) postdog.Transport

Transport returns a Gmail transport with the `gmail.GmailGoogleComScope` (https://mail.google.com/) scope.

Providing credentials

If the `GMAIL_CREDENTIALS` environment variable is not empty, the file at the given filepath will be used as the credentials file. Otherwise credentials must be provided with one of the CredentialsXXX() options.

Gmail service setup happens with the first call to Send(), if WithSender() option is not used. If the setup fails, Send() will return a *SetupError. If the setup fails due missing credentials, the error will unwrap to an ErrNoCredentials error.

Authentication will happen with the first call to Send(). If authentication fails, Send() will return a *SetupError.

Specifying scopes

Scopes may be specified with the Scopes() option. If no scopes are specified, only the `gmail.GmailGoogleComScope` will be used.

Types

type JWTConfigOption added in v0.6.8

type JWTConfigOption func(*jwt.Config)

JWTConfigOption configures a *jwt.Config.

func JWTSubject added in v0.6.8

func JWTSubject(subject string) JWTConfigOption

JWTSubject returns an Option that sets the `subject` field of the JWT config.

type Option

type Option func(*transport)

Option is an option for the Gmail transport.

func Credentials

func Credentials(creds *google.Credentials) Option

Credentials returns an Option that authenticates API calls using creds.

func CredentialsFile

func CredentialsFile(path string, opts ...JWTConfigOption) Option

CredentialsFile returns an Option that authenticates API calls using the credentials file at path.

Use the JWTSubject() option to specify the `subject` field of the parsed JWT config.

func CredentialsJSON

func CredentialsJSON(jsonKey []byte, opts ...JWTConfigOption) Option

CredentialsJSON returns an Option that authenticates API calls using the credentials file in jsonKey.

Use the JWTSubject() option to specify the `subject` field of the parsed *jwt.Config.

func Scopes

func Scopes(scopes ...string) Option

Scopes returns an Option that specifies the Gmail scopes.

func WithClientOptions added in v0.8.0

func WithClientOptions(opts ...option.ClientOption) Option

WithClientOptions returns an Option that adds custom option.ClientOptions that will be passed to the Sender factory.

func WithSender added in v0.8.0

func WithSender(s Sender) Option

WithSender returns an Option that sets the Sender for sending mails.

Using this option makes the following options no-ops: WithSenderFactory(), WithClientOptions(), WithTokenSource(), WithTokenSourceFactory(), CredentialsXXX(), JWTSubject()

func WithSenderFactory added in v0.8.0

func WithSenderFactory(
	newSender func(
		context.Context,
		oauth2.TokenSource,
		...option.ClientOption,
	) (Sender, error),
) Option

WithSenderFactory return an Option that sets the returned Sender of newSender as the Sender for sending mails.

Using this option makes the following options no-ops: WithClientOptions(), WithTokenSource(), WithTokenSourceFactory(), CredentialsXXX(), JWTSubject()

func WithTokenSource added in v0.8.0

func WithTokenSource(ts oauth2.TokenSource) Option

WithTokenSource returns an Option that sets ts as the oauth2.TokenSource to be passed as an option.ClientOption to the Sender factory.

Using this option makes the following options no-ops: WithTokenSourceFactory(), CredentialsXXX(), JWTSubject()

func WithTokenSourceFactory added in v0.8.0

func WithTokenSourceFactory(newTokenSource func(context.Context, ...string) (oauth2.TokenSource, error)) Option

WithTokenSourceFactory returns an Option that sets newTokenSource to be used as the oauth2.TokenSource factory.

Using this option makes the following options no-ops: CredentialsXXX(), JWTSubject()

type Sender added in v0.8.0

type Sender interface {
	Send(userID string, msg *gmail.Message) error
}

Sender wraps the *gmail.UsersMessagesService.Send().Do() method(s).

type SetupError added in v0.8.0

type SetupError struct {
	Err error
}

SetupError is an error that occurred during the initial setup of the Gmail service.

func (SetupError) Error added in v0.8.0

func (err SetupError) Error() string

func (SetupError) Unwrap added in v0.8.0

func (err SetupError) Unwrap() error

Directories

Path Synopsis
Package mock_gmail is a generated GoMock package.
Package mock_gmail is a generated GoMock package.

Jump to

Keyboard shortcuts

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