Code Monkey home page Code Monkey logo

cake's Introduction

Stories in Ready

Cake (Email Delivery)

Provides support for composing emails from reusable templates and utilises the Swoosh library to provide support for delivering emails.

Usage

The service component (Cake.Service) is an OTP application that should be started prior to making any requests to the service. This component should only be interacted with to configure/control the service explicitly.

An API (Cake.API) is provided to allow for convenient interaction with the service from external applications.

An email composition library (Cake.Email) is provided to simplify the creation of emails.

Composing Emails

Emails can be created from a template or a pre-existing email representation. Email templates are reusable maps that can be used to generate an email representation.

defmodule InvoiceTemplate do
    defstruct [
        formatter: &InvoiceTemplate.format/1,
        client: nil,
        amount: nil,
        date: nil
    ]

    def format(%{ client: { name, email }, amount: amount, date: date }) do
        %Cake.Email{
            from: "[email protected]",
            to: email,
            subject: "Invoice for #{date}",
            body: %Cake.Email.Body{
                text: "Hi #{name}, your account was billed #{amount} for the period (#{date})."
            }
        }
    end
end

Cake.API.Mailer.post(%InvoiceTemplate{ client: { "Foo", "foo@bar" }, amount: "$100", date: "January" })

To see more on how composing works see Cake.Email.compose/2.

Todo

  • Normalise success and failure results for the API (so it isn't dependent on swoosh adapter).

cake's People

Contributors

scrimpycat avatar waffle-iron avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.