Giter Club home page Giter Club logo

mailer's Introduction

Mailer

This project aims to provide a common api for popular email providers. It currently supports

  • Mailgun
  • Sendgrid

I also plan to add a wrapper for SMTP

Installation

Add this to your application's shard.yml:

dependencies:
  mailer:
    github: crisward/mailer

Usage

require "mailer"

Mailer.config(provider: Mailer::Mailgun.new(key: ENV["MAILGUN_KEY"], domain: ENV["MAILGUN_DOMAIN"]))
email = Mailer::Message.new
email.to("[email protected]","their_name")
email.from = "[email protected]"
email.subject = "Hello"
email.text = "Some plain text messaeg"
email.html = "<p>Some html message <img src='cid:logo.jpg'></p>"
email.attachment = Mailer::Attachment.new(filename: "test.pdf" , path: "./spec/test.pdf")
email.inline = Mailer::Attachment.new(filename: "logo.jpg" , path: "./spec/test.png")
email.send

To use sendgrid, swap the first line to

Mailer.config(provider: Mailer::Sendgrid.new(key: "your sendgrid api key"))

Testing Your App

While testing your app, you probably won't want to send real emails. You can use the built in Mock provider for this.

# eg for kemal
if ENV["KEMAL_ENV"]? != "test"
  Mailer.config(provider: Mailer::Mailgun.new(key: ENV["MAILGUN_KEY"], domain: ENV["MAILGUN_DOMAIN"]))
else
  Mailer.config(provider:Mailer::Mock.new())
end

Development

Running tests

# mock
crystal spec

#mailgun
MAILGUN_KEY="your-api-key" MAILGUN_DOMAIN="mailgun-domain" EMAIL="[email protected]" crystal spec

#sendgrid
SENDGRID_KEY="your-api-key" EMAIL="[email protected]" crystal spec

Todo

This library isn't full baked. It works, but there are some thing which need adding

  • Error Handling
  • Logging
  • Adding SMTP option

Contributing

  1. Fork it ( https://github.com/crisward/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

Contributors

mailer's People

Contributors

crisward avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

mailer's Issues

Kemal??

What is this line doing here?

if ENV["KEMAL_ENV"]? != "test" # prevent accidental email sending in kemal

If this is a shard to send mails for kemal it should be called kemal_mailer or something like that.

If possible, I'd like shards in Crystal to avoid what happens in Ruby: Ruby is Rails, so let's make every gem know about Rails, just in case...

Could this be modeled in a different way?

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.