parkerduckworth / bamboo_gmail

Gmail Adapter for Bamboo
MIT License
3 stars 1 forks source link

Support Goth 1.4 and multiple service accounts #12

Open entone opened 1 month ago

entone commented 1 month ago

Not sure I can open a PR across GitLab -> GitHub, but just wanted to let anyone know that's interested, I have a fork that supports Goth 1.4 and multiple service accounts. Also made some changes to support display name in the from address and content id's for attachments.

Check it out here. https://gitlab.com/frontlinewildfire/bamboo_gmail/

The only change required in the config is to remove sub and add a goth_mod key and value. eg;

config :frontline, Frontline.Mailer,
  adapter: Bamboo.GmailAdapter,
  goth_mod: Frontline.GmailAccount,
  sandbox: false

In your app where you setup Goth you would do something like this.

credentials =
        "GMAIL_SERVICE_ACCOUNT"
        |> System.fetch_env!()
        |> File.read!()
        |> Jason.decode!()

      claims = %{
        "sub" => "hello@frontlinewildfire.com",
        "scope" => "https://www.googleapis.com/auth/gmail.send"
      }

      source = {:service_account, credentials, claims: claims}

      [
        Supervisor.child_spec({Goth, name: Frontline.Goth}, id: Frontline.Goth),
        Supervisor.child_spec({Goth, name: Frontline.GmailAccount, source: source},
          id: Frontline.GmailAccount
        )
      ]

In this instance GmailAccount will use the credentials read into the credentials var above and Frontline.Goth will look for creds in the GOOGLE_APPLICATION_CREDENTIALS env var.

parkerduckworth commented 1 month ago

Very cool @entone thanks for sharing this. Unfortunately I don’t have the time to maintain this any longer. Will leave this open for visibility