Proca.Service.EmailBackend behaviour (proca v3.0.2)

EmailBackend behaviour specifies what we want to expect from an email backend. We are using Bamboo for sending emails - it is very convenient because it has lots of adapters. However, we also need to be able to work with templates and Bamboo does not have this.

Recipients

Recipients of transaction emails are Supporters.

  1. We prefer to use a template system, for sending emails in batch.
  2. If this is not available, send them one by one

Templates

We want to avoid having an email template editor in Proca.

  1. We prefer using template if there is web editor for templates
  2. We can also pull the content from a CMS, push as template
  3. We can use email template from ActionPage.config

Link to this section Summary

Functions

Delivers an email using EmailTemplate to a list of EmailRecipients. Uses Org's email service. Can throw EmailBackend.NotDelivered which wraps service error.

Link to this section Types

Specs

recipient() :: %Proca.Service.EmailRecipient{
  email: term(),
  fields: term(),
  first_name: term(),
  ref: term()
}

Link to this section Callbacks

Link to this callback

deliver(%Bamboo.Email{}, %Proca.Org{})

Specs

deliver(
  %Bamboo.Email{
    assigns: term(),
    attachments: term(),
    bcc: term(),
    cc: term(),
    from: term(),
    headers: term(),
    html_body: term(),
    private: term(),
    subject: term(),
    text_body: term(),
    to: term()
  },
  %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  }
) :: any()
Link to this callback

get_template(org, ref)

Specs

get_template(
  org :: %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  },
  ref :: String.t()
) ::
  {:ok,
   %Proca.Service.EmailTemplate{
     html: term(),
     name: term(),
     ref: term(),
     subject: term(),
     text: term()
   }}
  | {:error, reason :: String.t()}
Link to this callback

list_templates(org)

Specs

list_templates(
  org :: %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  }
) ::
  {:ok,
   [
     %Proca.Service.EmailTemplate{
       html: term(),
       name: term(),
       ref: term(),
       subject: term(),
       text: term()
     }
   ]}
  | {:error, reason :: String.t()}
Link to this callback

put_recipients(email, recipients)

Specs

put_recipients(
  email :: %Bamboo.Email{
    assigns: term(),
    attachments: term(),
    bcc: term(),
    cc: term(),
    from: term(),
    headers: term(),
    html_body: term(),
    private: term(),
    subject: term(),
    text_body: term(),
    to: term()
  },
  recipients :: [recipient()]
) :: %Bamboo.Email{
  assigns: term(),
  attachments: term(),
  bcc: term(),
  cc: term(),
  from: term(),
  headers: term(),
  html_body: term(),
  private: term(),
  subject: term(),
  text_body: term(),
  to: term()
}
Link to this callback

put_reply_to(email, reply_to_email)

Specs

put_reply_to(
  email :: %Bamboo.Email{
    assigns: term(),
    attachments: term(),
    bcc: term(),
    cc: term(),
    from: term(),
    headers: term(),
    html_body: term(),
    private: term(),
    subject: term(),
    text_body: term(),
    to: term()
  },
  reply_to_email :: String.t()
) :: %Bamboo.Email{
  assigns: term(),
  attachments: term(),
  bcc: term(),
  cc: term(),
  from: term(),
  headers: term(),
  html_body: term(),
  private: term(),
  subject: term(),
  text_body: term(),
  to: term()
}
Link to this callback

put_template(email, template)

Specs

put_template(
  email :: %Bamboo.Email{
    assigns: term(),
    attachments: term(),
    bcc: term(),
    cc: term(),
    from: term(),
    headers: term(),
    html_body: term(),
    private: term(),
    subject: term(),
    text_body: term(),
    to: term()
  },
  template :: %Proca.Service.EmailTemplate{
    html: term(),
    name: term(),
    ref: term(),
    subject: term(),
    text: term()
  }
) :: %Bamboo.Email{
  assigns: term(),
  attachments: term(),
  bcc: term(),
  cc: term(),
  from: term(),
  headers: term(),
  html_body: term(),
  private: term(),
  subject: term(),
  text_body: term(),
  to: term()
}
Link to this callback

supports_templates?(org)

Specs

supports_templates?(
  org :: %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  }
) :: true | false
Link to this callback

upsert_template(org, template)

Specs

upsert_template(
  org :: %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  },
  template :: %Proca.Service.EmailTemplate{
    html: term(),
    name: term(),
    ref: term(),
    subject: term(),
    text: term()
  }
) :: :ok | {:error, reason :: String.t()}

Link to this section Functions

Link to this function

deliver(recipients, org, email_template)

Specs

deliver(
  [
    %Proca.Service.EmailRecipient{
      email: term(),
      fields: term(),
      first_name: term(),
      ref: term()
    }
  ],
  %Proca.Org{
    __meta__: term(),
    action_pages: term(),
    action_schema_version: term(),
    campaigns: term(),
    config: term(),
    confirm_processing: term(),
    contact_schema: term(),
    custom_action_confirm: term(),
    custom_action_deliver: term(),
    custom_supporter_confirm: term(),
    email_backend: term(),
    email_backend_id: term(),
    email_from: term(),
    email_opt_in: term(),
    email_opt_in_template: term(),
    event_backend: term(),
    event_backend_id: term(),
    event_processing: term(),
    high_security: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    public_keys: term(),
    services: term(),
    staffers: term(),
    system_sqs_deliver: term(),
    template_backend: term(),
    template_backend_id: term(),
    title: term(),
    updated_at: term()
  },
  %Proca.Service.EmailTemplate{
    html: term(),
    name: term(),
    ref: term(),
    subject: term(),
    text: term()
  }
) :: :ok

Delivers an email using EmailTemplate to a list of EmailRecipients. Uses Org's email service. Can throw EmailBackend.NotDelivered which wraps service error.

Link to this function

list_templates(org)

Link to this function

service_module(atom)

Link to this function

supports_templates?(org)

Link to this function

via_from(arg1, arg2)