remail 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.markdown +59 -0
- data/Rakefile +13 -0
- data/VERSION +1 -0
- data/lib/remail.rb +74 -0
- data/remail.gemspec +44 -0
- metadata +78 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/README.markdown
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Remail is RESTful email for Rails.
|
2
|
+
|
3
|
+
Forget configuring SMTP servers and queues, just use Remail.
|
4
|
+
Remail uses Google App Engine to send and receive emails RESTfully.
|
5
|
+
|
6
|
+
Remail only support Rails 3.
|
7
|
+
|
8
|
+
Google App Engine gives you a free quota of 2000 emails per day or, with the
|
9
|
+
paid version, 7,400,000 emails per day.
|
10
|
+
|
11
|
+
## Features
|
12
|
+
* POST emails to your Remail App Engine in order to send them
|
13
|
+
* Remail POSTS received emails back to a configurable URL
|
14
|
+
|
15
|
+
## Setup
|
16
|
+
* Configure and deploy the [Remail App Engine](http://github.com/maccman/remail-engine)
|
17
|
+
* Install the Remail gem (sudo gem install remail)
|
18
|
+
|
19
|
+
## Sending email
|
20
|
+
Configure ActionMailer and Remail:
|
21
|
+
|
22
|
+
config.action_mailer.delivery_method = :remail
|
23
|
+
config.action_mailer.remail_settings = {
|
24
|
+
:app_id => "remail-appname",
|
25
|
+
:api_key => "changeme"
|
26
|
+
}
|
27
|
+
|
28
|
+
The sender address of a message must be the email address of an administrator for the Remail App Engine.
|
29
|
+
If you want to send email on behalf of the application but do not want to use a single administrator's personal Google Account as the sender, you can create a new Google Account for the application using any valid email address, then add the new account as an administrator for the application.
|
30
|
+
|
31
|
+
## Receiving email
|
32
|
+
* Configure the callback URL in your Remail App Engine.
|
33
|
+
* Create a email controller, that looks a bit like this (remember to configure the routes):
|
34
|
+
|
35
|
+
class EmailsController < ApplicationController
|
36
|
+
skip_before_filter :verify_authenticity_token
|
37
|
+
|
38
|
+
def create
|
39
|
+
if request.headers["Authorization"] != your_api_key
|
40
|
+
return head(:unauthorized)
|
41
|
+
end
|
42
|
+
UserMailer.receive(params[:email][:raw])
|
43
|
+
head :success
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
The API key is also passed through as an Authorization header,
|
48
|
+
you should definitely validate that.
|
49
|
+
|
50
|
+
You might want to add :email to the filter_parameters configuration, you
|
51
|
+
don't want your logs being clogged up with emails.
|
52
|
+
|
53
|
+
Your app can receive email at addresses of the following form:
|
54
|
+
string@appid.appspotmail.com
|
55
|
+
|
56
|
+
## Misc
|
57
|
+
|
58
|
+
To ensure your email doesn't get caught in spam filters, you should follow
|
59
|
+
the tips in this tutorial I [wrote](http://madebymany.co.uk/getting-email-around-spam-filters-00221) - the important points being setting SPF and MX records.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require "jeweler"
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "remail"
|
5
|
+
gemspec.summary = "RESTful email"
|
6
|
+
gemspec.email = "info@eribium.org"
|
7
|
+
gemspec.homepage = "http://github.com/maccman/remail"
|
8
|
+
gemspec.authors = ["Alex MacCaw"]
|
9
|
+
gemspec.add_dependency("activeresource")
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
13
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/remail.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "active_resource"
|
2
|
+
|
3
|
+
module Remail
|
4
|
+
def site=(site)
|
5
|
+
Email.site = site
|
6
|
+
end
|
7
|
+
module_function :site=
|
8
|
+
|
9
|
+
def app_id=(name)
|
10
|
+
self.site = "http://#{name}.appspot.com"
|
11
|
+
end
|
12
|
+
module_function :app_id=
|
13
|
+
|
14
|
+
def api_key=(key)
|
15
|
+
Email.headers["Authorization"] = key
|
16
|
+
end
|
17
|
+
module_function :api_key=
|
18
|
+
|
19
|
+
class Email < ActiveResource::Base
|
20
|
+
self.timeout = 5
|
21
|
+
self.format = :json
|
22
|
+
|
23
|
+
cattr_accessor :headers
|
24
|
+
@@headers = {}
|
25
|
+
|
26
|
+
schema do
|
27
|
+
string :sender, :to, :cc, :bcc,
|
28
|
+
:reply_to, :subject,
|
29
|
+
:body, :html
|
30
|
+
end
|
31
|
+
|
32
|
+
validates_presence_of :sender, :to, :subject
|
33
|
+
validates_presence_of :body, :unless => :html?
|
34
|
+
|
35
|
+
# The sender address must be the email address of a
|
36
|
+
# registered administrator for the application
|
37
|
+
def from=(address)
|
38
|
+
self.sender = address
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class ActionMailer
|
43
|
+
def initialize(settings)
|
44
|
+
settings.each {|key, value|
|
45
|
+
Remail.send("#{key}=", value)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def deliver!(mail)
|
50
|
+
remail = Remail::Email.new
|
51
|
+
|
52
|
+
%w{to from cc bcc reply_to}.each {|attr|
|
53
|
+
value = mail.send(attr)
|
54
|
+
next unless value
|
55
|
+
remail.send("#{attr}=", value.join(", "))
|
56
|
+
}
|
57
|
+
|
58
|
+
remail.subject = mail.subject
|
59
|
+
|
60
|
+
text_body = mail.text_part ? mail.text_part.body : mail.body
|
61
|
+
html_body = mail.html_part && mail.html_part.body
|
62
|
+
remail.body = text_body.encoded if text_body
|
63
|
+
remail.html = html_body.encoded if html_body
|
64
|
+
|
65
|
+
remail.save!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
require "action_mailer"
|
72
|
+
ActionMailer::Base.add_delivery_method(:remail, Remail::ActionMailer)
|
73
|
+
rescue LoadError
|
74
|
+
end
|
data/remail.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{remail}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex MacCaw"]
|
12
|
+
s.date = %q{2010-03-22}
|
13
|
+
s.email = %q{info@eribium.org}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.markdown"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/remail.rb",
|
23
|
+
"remail.gemspec"
|
24
|
+
]
|
25
|
+
s.homepage = %q{http://github.com/maccman/remail}
|
26
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.rubygems_version = %q{1.3.6}
|
29
|
+
s.summary = %q{RESTful email}
|
30
|
+
|
31
|
+
if s.respond_to? :specification_version then
|
32
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
33
|
+
s.specification_version = 3
|
34
|
+
|
35
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
36
|
+
s.add_runtime_dependency(%q<activeresource>, [">= 0"])
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<activeresource>, [">= 0"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: remail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alex MacCaw
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-22 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activeresource
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description:
|
33
|
+
email: info@eribium.org
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README.markdown
|
40
|
+
files:
|
41
|
+
- .gitignore
|
42
|
+
- README.markdown
|
43
|
+
- Rakefile
|
44
|
+
- VERSION
|
45
|
+
- lib/remail.rb
|
46
|
+
- remail.gemspec
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/maccman/remail
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: RESTful email
|
77
|
+
test_files: []
|
78
|
+
|