GithubHelp home page GithubHelp logo

kevintom / sendwithus_ruby_action_mailer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sendwithus/sendwithus_ruby_action_mailer

0.0 1.0 0.0 134 KB

sendwithus rails action mailer

License: MIT License

Ruby 100.00%

sendwithus_ruby_action_mailer's Introduction

sendwithus Ruby Action Mailer

sendwithus is a service that provides a convenient way for non-developers to create and edit the email content from your app. sendwithus has created a gem, send_with_us, that communicates with our REST API for sending templated emails.

Ruby on Rails developers are familiar with the ActionMailer interface for sending email. This gem implements a small layer over the send_with_us gem that provides and ActionMailer-like API.

Installation

Add this line to your application's Gemfile:

gem 'sendwithus_ruby_action_mailer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sendwithus_ruby_action_mailer

Setup

Rails

For a Rails app, create send_with_us.rb in /config/initializers/ with the following:

SendWithUs::Api.configure do |config|
    config.api_key = 'YOUR API KEY'
    config.debug = true
end

Usage

Mailer models inherit from SendWithUsMailer::Base. A mailer model defines methods used to generate an email message. In these methods, you can assign variables to be sent to the Send With Us service and options on the mail itself such as the :from address.

class Notifier < SendWithUsMailer::Base
    default from: '[email protected]'

    def welcome(recipient)
        assign(:account, recipient)

        assign(:captain_name, recipient.name)
        #=> in sendwithus email template {{ captain_name }}
        assign :team, {team_name: recipient.team_name, captain: recipient.name}
        #=> in sendwithus email template {{ team.team_name }} and {{ team.captain }} 

        mail(
            email_id: 'ID-CODE-FROM-SEND-WITH-US',
            recipient_address: recipient.email,
            from_name: 'Billing',
            from_address: '[email protected]',
            reply_to: '[email protected]',
            bcc: [{:address => "[email protected]"},{:address => "[email protected]"}],
            version_name: 'en-US')
    end
end

Within the mailer method, you have access to the following methods:

  • assign - Allows you to assign key-value pairs that will be data payload used by Send With Us within the email.
  • mail - Allows you to specify the email to be sent.

Sending mail

Once a mailer action is defined, you can deliver your message or create it and save it for delivery later:

Notifier.welcome(nick).deliver # sends the email

mail = Notifier.welcome(david)  # => a SendWithUsMailer::MailParams object
mail.deliver                    # sends the email

You never instantiate your mailer class. Rather, you just call the method you defined on the class itself.

Default Hash

SendWithUsMailer allows you to specify default values inside the class definition:

class Notifier < SendWithUsMailer::Base
    default from: '[email protected]'
end

Contributing

  1. Fork it
  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 new Pull Request

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.