Documentation ¶
Index ¶
- Variables
- func Factory(_ context.Context, cfg map[string]interface{}) (postdog.Transport, error)
- func Transport(opts ...Option) postdog.Transport
- type JWTConfigOption
- type Option
- func Credentials(creds *google.Credentials) Option
- func CredentialsFile(path string, opts ...JWTConfigOption) Option
- func CredentialsJSON(jsonKey []byte, opts ...JWTConfigOption) Option
- func Scopes(scopes ...string) Option
- func WithClientOptions(opts ...option.ClientOption) Option
- func WithSender(s Sender) Option
- func WithSenderFactory(...) Option
- func WithTokenSource(ts oauth2.TokenSource) Option
- func WithTokenSourceFactory(newTokenSource func(context.Context, ...string) (oauth2.TokenSource, error)) Option
- type Sender
- type SetupError
Constants ¶
This section is empty.
Variables ¶
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
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
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
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 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
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 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