• Stars
    star
    309
  • Rank 135,306 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Incoming! helps you receive email in your Rack apps.

Incoming!

Receive email in your Rack apps.

Incoming! receives a Rack::Request and hands you a Mail::Message, much like ActionMailer::Base.receive does with a raw email. We currently support the following services:

  • SendGrid
  • Mailgun
  • Postmark
  • CloudMailin
  • Mandrill
  • Any mail server capable of routing messages to a system command

Brought to you by ⚑ Honeybadger.io, painless Rails exception tracking.

Build Status Gem Version

Installation

  1. Add Incoming! to your Gemfile and run bundle install:

    gem "incoming"
  2. Create a new class to receive emails (see examples below)

  3. Implement an HTTP endpoint to receive HTTP post hooks, and pass the request to your receiver. (see examples below)

SendGrid Example

class EmailReceiver < Incoming::Strategies::SendGrid
  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

Sendgrid API reference

Mailgun Example

class EmailReceiver < Incoming::Strategies::Mailgun
  setup api_key: "asdf"

  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

Mailgun API reference

Postmark Example

class EmailReceiver < Incoming::Strategies::Postmark
  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

Postmark API reference

CloudMailin Example

Use the Raw Format when setting up your address target.

class EmailReceiver < Incoming::Strategies::CloudMailin
  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

CloudMailin API reference

Mandrill Example

Mandrill is capable of sending multiple events in a single webhook, so the Mandrill strategy works a bit differently than the others. Namely, the .receive method returns an Array of return values from your #receive method for each inbound event in the payload. Otherwise, the implementation is the same:

class EmailReceiver < Incoming::Strategies::Mandrill
  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

Mandrill API reference

Postfix Example

class EmailReceiver < Incoming::Strategies::HTTPPost
  setup secret: "6d7e5337a0cd69f52c3fcf9f5af438b1"

  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"
# /etc/postfix/virtual
@example.com http_post

# /etc/mail/aliases
http_post: "|http_post -s 6d7e5337a0cd69f52c3fcf9f5af438b1 http://www.example.com/emails"

Qmail Example:

class EmailReceiver < Incoming::Strategies::HTTPPost
  setup secret: "6d7e5337a0cd69f52c3fcf9f5af438b1"

  def receive(mail)
    %(Got message from #{mail.to.first} with subject "#{mail.subject}")
  end
end

req = Rack::Request.new(env)
result = EmailReceiver.receive(req) # => Got message from [email protected] with subject "hello world"

To setup a global incoming email alias:

# /var/qmail/alias/.qmail-whoever - mails to whoever@ will be delivered to this alias.
|http_post -s 6d7e5337a0cd69f52c3fcf9f5af438b1 http://www.example.com/emails

Domain-specific incoming aliases can be set as follows:

#/var/qmail/control/virtualdomains
example.com:example

#~example/.qmail-whoever
|http_post -s 6d7e5337a0cd69f52c3fcf9f5af438b1 http://www.example.com/emails

Now mails to [email protected] will be posted to the corresponding URL above. To post all mails for example.com, just add the above line to ~example/.qmail-default.

Example Rails Controller

# app/controllers/emails_controller.rb
class EmailsController < ActionController::Base
  def create
    if EmailReceiver.receive(request)
      render json: { status: "ok" }
    else
      render json: { status: "rejected" }, status: 403
    end
  end
end
# config/routes.rb
Rails.application.routes.draw do
  post "/emails" => "emails#create"
end
# spec/controllers/emails_controller_spec.rb
require "spec_helper"

describe EmailsController, "#create" do
  it "responds with success when request is valid" do
    allow(EmailReceiver).to receive(:receive).and_return(true)
    post :create
    expect(response.success?).to eq(true)
    expect(response.body).to eq(%({"status":"ok"}))
  end

  it "responds with 403 when request is invalid" do
    allow(EmailReceiver).to receive(:receive).and_return(false)
    post :create
    expect(response.status).to eq(403)
    expect(response.body).to eq(%({"status":"rejected"}))
  end
end

TODO

  1. Provide authentication for all strategies where possible (currently only Mailgun requests are authenticated.)

Contributing

  1. Fork it.
  2. Create a topic branch git checkout -b my_branch
  3. Commit your changes git commit -am "Boom"
  4. Push to your branch git push origin my_branch
  5. Send a pull request

License

Incoming! is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

More Repositories

1

heya

Heya πŸ‘‹ is a campaign mailer for Rails. Think of it like ActionMailer, but for timed email sequences. It can also perform other actions like sending a text message.
Ruby
732
star
2

honeybadger-ruby

Ruby gem for reporting errors to honeybadger.io
Ruby
244
star
3

honeybadger-elixir

Elixir client for Honeybadger.
Elixir
181
star
4

honeybadger-js

Universal JavaScript library for reporting errors to Honeybadger.io ⚑
TypeScript
109
star
5

pg_partition_manager

Manage PostgreSQL table partitions
Ruby
67
star
6

honeybadger-laravel

PHP/Laravel library for reporting errors to Honeybadger.io 🐘 ⚑
PHP
39
star
7

honeybadger-php

PHP library for reporting errors to Honeybadger.io 🐘 ⚑
PHP
37
star
8

honeybadger-go

Send Go (golang) panics and errors to Honeybadger.
Go
35
star
9

serverless-quickstart

A boilerplate project for getting started with Serverless/Node ⚑
JavaScript
33
star
10

honeybadger-webpack

A webpack plugin to send sourcemaps to Honeybadger
JavaScript
29
star
11

honeybadger-node

A node.js notifier for honeybadger.io
JavaScript
21
star
12

honeybadger-crystal

Crystal library for reporting errors to Honeybadger.io πŸ’Ž ⚑
Crystal
16
star
13

honeybadger-python

Send Python and Django errors to Honeybadger.
Python
15
star
14

nextjs-with-honeybadger

This is an example of how to use Honeybadger to catch & report errors on both client + server side in Next.js.
JavaScript
15
star
15

honeybadger-react

Official React integration for Honeybadger.io ⚑
TypeScript
14
star
16

honeybadger-vue

Official Vue.js integration for Honeybadger.io ⚑
JavaScript
11
star
17

github-notify-deploy-action

Send deployment notifications to Honeybadger via GitHub Actions
Shell
10
star
18

honeybadger-lambda-node

A Node template for AWS Lamda which reports errors to Honeybadger.io
JavaScript
10
star
19

honeybadger-java

Java Client to report exceptions to Honeybadger.io
Java
10
star
20

reck

🐍 Reck: the exception-powered Ruby web framework! 🐍
Ruby
9
star
21

honeybadger-rails-webpacker-example

Example Rails 5.1/Webpacker app with support for Source Maps in Honeybadger
Ruby
6
star
22

yabeda-honeybadger_insights

Yabeda integration with Honeybadger Insights
Ruby
6
star
23

github-upload-sourcemap-action

Upload source maps to Honeybadger via GitHub Actions
Shell
5
star
24

nova-honeybadger

Official Laravel Nova package for Honeybadger.io 🐘 ⚑
PHP
5
star
25

heya-app

This is my testbed/example Rails app for the heya gem.
Ruby
4
star
26

delayed_job_honeybadger

Notifies Honeybadger of errors in Delayed Job workers.
Ruby
4
star
27

honeybadger-dotnet

C#
3
star
28

crywolf-node

Honeybadger example for Node.JS
JavaScript
3
star
29

crywolf-elixir

Honeybadger example for Elixir
Elixir
3
star
30

honeybadger-react-native

Official React Native integration for Honeybadger.io ⚑
JavaScript
2
star
31

honeybadger-cocoa

Official Objective-C & Swift library for reporting errors and crashes to Honeybadger.io 🍎 ⚑
Objective-C
2
star
32

unicorn

Ruby
1
star
33

rpush-plugin

Rpush plugin for Honeybadger
Ruby
1
star
34

circleci-orb

CircleCI Orb that interacts with the Honeybadger.io API.
1
star
35

honeybadger-sinatra-example

Example sinatra app reporting errors w/ Honeybadger
Ruby
1
star
36

examples-react-on-rails

A simple example of how to integrate Honeybadger with React on Rails to unlock Universal (Isomorphic) error reporting in your React-based Rails apps.
Ruby
1
star
37

examples-rails

A sample Rails app for trying Honeybadger.io
Ruby
1
star