Git Product home page Git Product logo

quartz-mailer's Introduction

Quartz-Mailer

Build Status

A library to send emails from your Crystal application.

Installation

Add this to your application's shard.yml:

dependencies:
  quartz_mailer:
    github: amberframework/quartz-mailer

Usage

require "quartz_mailer"

The mailer has the ability to set the from, to, cc, bcc, and subject as well as both text and html body formats. You can also add custom headers using header method.

A render helper provides friendly markup rendering with jeromegn/kilt.

class WelcomeMailer < Quartz::Composer
  def sender
    address email: "[email protected]", name: "Amber"
  end

  def initialize(name : String, email : String)
    to name: name, email: email # Can be called multiple times to add more recipients
    subject "Welcome to Amber"
    header "X-Custom-Header", "value" # Can be called multiple times to add more custom headers
    text render("mailers/welcome_mailer.text.ecr")
    html render("mailers/welcome_mailer.html.slang", "mailer-layout.html.slang")
  end
end

To deliver a new email:

WelcomeMailer.new(name, email).deliver

To remove a recipient:

remove_to_recipient email: "[email protected]"
remove_cc_recipient email: "[email protected]"
remove_bcc_recipient email: "[email protected]"

Multiple Recipient Example:

class MultipleRecipientMailer < Quartz::Composer
  def sender
    address email: "[email protected]", name: "Amber"
  end

  def initialize(to_emails : Array(String), cc_emails = [] of String, bcc_emails = [] of String, headers = {} of String => String)
    to_emails.each do |email|
      to email
    end

    cc_emails.each do |email|
      cc email
    end

    bcc_emails.each do |email|
      bcc email
    end

    headers.each do |name, value|
      header name, value
    end

    subject "Welcome to Amber"
    text render("mailers/welcome_mailer.text.ecr")
    html render("mailers/welcome_mailer.html.slang", "mailer-layout.html.slang")
  end
end

MultipleRecipientMailer.new(email_addrs, cc_email_addrs, bcc_email_addrs).deliver

Contributing

  1. Fork it ( https://github.com/amber-crystal/quartz-mailer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

quartz-mailer's People

Contributors

anamba avatar andilavera avatar d1ceward avatar damianham avatar dare892 avatar drujensen avatar eliasjpr avatar faustinoaq avatar robacarp avatar westonganger avatar zaidakram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quartz-mailer's Issues

Error resolving kilt (~> 0.3.3, ~> 0.4.0) on shards update

Hi, I've been getting this error when trying shards update on a new amber project.

Updating https://github.com/amberframework/amber.git
Updating https://github.com/luislavena/radix.git
Updating https://github.com/jeromegn/kilt.git
Updating https://github.com/jeromegn/slang.git
Updating https://github.com/stefanwille/crystal-redis.git
Updating https://github.com/mosop/cli.git
Updating https://github.com/mosop/optarg.git
Updating https://github.com/mosop/callback.git
Updating https://github.com/mosop/string_inflection.git
Updating https://github.com/mosop/teeplate.git
Updating https://github.com/TechMagister/crystal-icr.git
Updating https://github.com/TechMagister/sentry.git
Updating https://github.com/juanedi/micrate.git
Updating https://github.com/crystal-lang/crystal-db.git
Updating https://github.com/jwaldrip/shell-table.cr.git
Updating https://github.com/askn/spinner.git
Updating https://github.com/will/crystal-pg.git
Updating https://github.com/crystal-lang/crystal-mysql.git
Updating https://github.com/crystal-lang/crystal-sqlite3.git
Updating https://github.com/amberframework/granite-orm.git
Updating https://github.com/amberframework/quartz-mailer.git
Error resolving kilt (~> 0.3.3, ~> 0.4.0)

My shard.yml file

name: amber
version: 0.1.0

authors:
  - Amber <amberframework.org>

crystal: 0.23.1

license: UNLICENSED

targets:
  amber:
    main: src/amber.cr

  amber:
    main: lib/amber/src/amber/cli.cr

dependencies:
  amber:
    github: amberframework/amber
    version: 0.3.0

  granite_orm:
    github: amberframework/granite-orm

  quartz_mailer:
    github: amberframework/quartz-mailer

  jasper_helpers:
    github: amberframework/jasper-helpers

  pg:
    github: will/crystal-pg

  jennifer:
    github: imdrasil/jennifer.cr

  sam:
    github: imdrasil/sam.cr

development_dependencies:
  amber_spec:
    github: amberframework/amber-spec

I noticed your last commit was upgrading kilt to 4.0 so it may related to that, but since this is my first Crystal app, let alone amber, I don't know how to troubleshoot it.

Receiving emails

Is there a way to process incoming emails in crystal using this with amber?

I might have missed it in the docs but I didn't see anything about how one could potentially receive / treat incoming emails.

Needs deployment documentation

Could you please add in to the README a section on how to figure out what values to give the SMTP environment variables? It's a little tricky to infer from code.

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.