View Source Swoosh.Adapters.Gmail (Swoosh v1.11.1)
An adapter that sends email using Gmail api
For reference: Gmail API docs
This adapter requires an API Client. Swoosh comes with Hackney and Finch out of the box. See the installation section for details.
dependency
Dependency
Gmail adapter requires Mail
dependency to format message as RFC 2822 message.
{:mail, ">= 0.0.0"}
Because Mail
library removes Bcc headers, they are being added after email is
rendered, in adapter code.
example
Example
# config/config.exs
config :sample, Sample.Mailer,
adapter: Swoosh.Adapters.Gmail,
access_token: {:system, "GMAIL_API_ACCESS_TOKEN"}
# To deal with token refresh, it could be a better idea to pass the access token
# in via deliver config explicitly, if you don't update the environment variable
# periodically. e.g.
MyMailer.deliver(my_email, access_token: my_access_token)
# lib/sample/mailer.ex
defmodule Sample.Mailer do
use Swoosh.Mailer, otp_app: :sample
end
required-config-parameters
Required config parameters
:access_token
valid OAuth2 access token Required scopes:- gmail.compose See https://developers.google.com/oauthplayground when developing
Link to this section Summary
Functions
Callback implementation for Swoosh.Adapter.validate_config/1
.
Callback implementation for Swoosh.Adapter.validate_dependency/0
.
Link to this section Functions
Callback implementation for Swoosh.Adapter.validate_config/1
.
Callback implementation for Swoosh.Adapter.validate_dependency/0
.