Search documentation of phoenix_kit

# PhoenixKit.Emails.ApplicationIntegration (phoenix_kit v1.6.19)

View Source

Helpers for integrating PhoenixKit Email Tracking into parent applications.

This module provides convenient functions for adding email system to your Phoenix application's supervision tree.

## Quick Integration

The simplest way to add email system:

    # In lib/your_app/application.ex
    def start(_type, _args) do
      children = [
        # ... your processes
      ] ++ PhoenixKit.Emails.ApplicationIntegration.children()

      Supervisor.start_link(children, strategy: :one_for_one)
    end

## Conditional Integration

If you want to control when email system starts:

    # In lib/your_app/application.ex
    def start(_type, _args) do
      base_children = [
        # ... your main processes
      ]

      children = base_children ++ email_children()

      Supervisor.start_link(children, strategy: :one_for_one)
    end

    defp email_children do
      if email_enabled?() do
        PhoenixKit.Emails.ApplicationIntegration.children()
      else
        []
      end
    end

    defp email_enabled? do
      # Your logic for determining if email system is enabled
      System.get_env("EMAIL_TRACKING_ENABLED") == "true"
    end

## Advanced Integration

For full control use separate functions:

    children = [
      # ... your processes
    ] ++ PhoenixKit.Emails.ApplicationIntegration.supervisor_children()

# Summary

## Functions

children(opts \\ [])

Returns list of child specs for adding to supervision tree.

initialize_configuration()

Creates initial configuration for email system.

preflight_check()

Performs pre-flight checks for email system system.

ready_for_email_system?()

Checks if system is ready to start email system.

supervisor_child_spec(opts \\ [])

Returns child spec for email system supervisor.

supervisor_children(opts \\ [])

Returns only children for supervisor (without supervisor itself).

# Functions

# children(opts \\ [])

Returns list of child specs for adding to supervision tree.

This is the main function for email system integration.

## Options

- `:supervisor_name` - supervisor process name
- `:start_sqs_worker` - force enable/disable SQS Worker

## Examples

    # Basic usage
    children = PhoenixKit.Emails.ApplicationIntegration.children()

    # With custom options
    children = PhoenixKit.Emails.ApplicationIntegration.children(
      supervisor_name: MyApp.EmailSystemSupervisor,
      start_sqs_worker: true
    )

# initialize_configuration()

Creates initial configuration for email system.

Useful for initializing system with basic settings.

## Examples

    PhoenixKit.Emails.ApplicationIntegration.initialize_configuration()

# preflight_check()

Performs pre-flight checks for email system system.

Returns detailed report on system readiness.

## Examples

    iex> PhoenixKit.Emails.ApplicationIntegration.preflight_check()
    %{
      status: :ready,
      checks: %{
        email_enabled: true,
        sqs_polling_enabled: true,
        sqs_configuration: true,
        aws_credentials: true
      }
    }

# ready_for_email_system?()

Checks if system is ready to start email system.

## Examples

    iex> PhoenixKit.Emails.ApplicationIntegration.ready_for_email_system?()
    true

    iex> PhoenixKit.Emails.ApplicationIntegration.ready_for_email_system?()
    {:error, :email_disabled}

# supervisor_child_spec(opts \\ [])

Returns child spec for email system supervisor.

## Examples

    supervisor_spec = PhoenixKit.Emails.ApplicationIntegration.supervisor_child_spec()

# supervisor_children(opts \\ [])

Returns only children for supervisor (without supervisor itself).

Use if you want to add email system processes to existing supervisor.

## Examples

    # In your supervisor module
    def init(_opts) do
      children = [
        # ... your processes
      ] ++ PhoenixKit.Emails.ApplicationIntegration.supervisor_children()

      Supervisor.init(children, strategy: :one_for_one)
    end