gomig_mail_delivery 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/Rakefile +1 -0
- data/example/example.rb +19 -0
- data/gomig_mail_delivery.gemspec +31 -0
- data/lib/gomig_mail_delivery.rb +46 -0
- data/readme.md +119 -0
- data/spec/gomig_mail_delivery_spec.rb +43 -0
- metadata +116 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/example/example.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'gomig_mail_delivery'
|
2
|
+
|
3
|
+
Mail.defaults do
|
4
|
+
delivery_method Mail::GomigMailDelivery::Agent, {
|
5
|
+
:domain => '<your domain>.<tld>',
|
6
|
+
:login_account => '<admin_or_user_acount>',
|
7
|
+
:password => '<passwordD>',
|
8
|
+
:to_account => '<target_account>',
|
9
|
+
:mail_item_property => 'IS_DRAFT' # optional. other options: IS_INBOX, IS_SENT
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
mail = Mail.deliver do
|
14
|
+
from 'sender@domain.tld'
|
15
|
+
date Time.now
|
16
|
+
to 'recipient name <recipient@domain.tld>'
|
17
|
+
subject 'I\'m your draft'
|
18
|
+
body 'Ready to send when you are.'
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gomig_mail_delivery"
|
7
|
+
s.version = '0.0.1'
|
8
|
+
s.authors = ["Timo van Prooijen, eWaza"]
|
9
|
+
s.email = ["timo@ewaza.nl"]
|
10
|
+
s.homepage = "https://github.com/ewaza/gomig-mail-delivery"
|
11
|
+
s.summary = %q{
|
12
|
+
Extension for the Mail gem that provides 'migrating' to a google Apps account
|
13
|
+
}
|
14
|
+
s.description = %q{
|
15
|
+
Google Apps migration API mail delivery method is an extension for the Mail gem. It provides a delivery method based on the the Google Apps migration API. This API is only available for organization who uses Google Apps for Business, Education or ISPs. (unfortunately not for Gmail or the free edition)
|
16
|
+
|
17
|
+
Whenever your application needs to automatically generate complex emails, which have to be manually approved before they can get sent out; You can make life easy with this gem in combination with google apps. Instead of delivering the email the email will be stored in a, preconfigured users DRAFTS folder.
|
18
|
+
|
19
|
+
You could also integrate this gem with a CRM system in order to load templates for further manual completion.
|
20
|
+
}
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
|
27
|
+
# specify any dependencies here; for example:
|
28
|
+
s.add_development_dependency "rspec"
|
29
|
+
s.add_runtime_dependency "mail"
|
30
|
+
s.add_runtime_dependency "gdata"
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'gdata'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
module Mail
|
5
|
+
module GomigMailDelivery
|
6
|
+
class Agent
|
7
|
+
attr_accessor :settings
|
8
|
+
|
9
|
+
def initialize(settings={})
|
10
|
+
settings[:url] = "https://apps-apis.google.com/a/feeds/migration/2.0/#{settings[:domain]}/#{settings[:to_account]}/mail"
|
11
|
+
|
12
|
+
@gdata_client = GData::Client::Apps.new
|
13
|
+
@gdata_client.clientlogin "#{settings[:login_account]}@#{settings[:domain]}", settings[:password]
|
14
|
+
|
15
|
+
self.settings = settings
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver!(mail)
|
19
|
+
migrate_mail mail, settings[:url], settings[:mail_item_property]
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def atom_entry(mail_item_property)
|
24
|
+
<<-EOF
|
25
|
+
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
|
26
|
+
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/apps/2006#mailItem'/>
|
27
|
+
<atom:content xmlns:atom='http://www.w3.org/2005/Atom' type='message/rfc822' />
|
28
|
+
#{mail_item_property ? '<apps:mailItemProperty value=\'' + mail_item_property + '\'/>' : ''}
|
29
|
+
</entry>
|
30
|
+
EOF
|
31
|
+
end
|
32
|
+
|
33
|
+
def migrate_mail( mail, url, mail_item_property )
|
34
|
+
atom_plus_message_body = GData::HTTP::MimeBody.new(atom_entry(mail_item_property), StringIO.new(mail.to_s), 'message/rfc822' )
|
35
|
+
@gdata_client.headers['Slug'] = 'migrated_mail'
|
36
|
+
@gdata_client.headers['MIME-Version'] = '1.0'
|
37
|
+
@gdata_client.headers['Content-Type'] = atom_plus_message_body.content_type
|
38
|
+
@gdata_client.make_request(:post, url, atom_plus_message_body)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
data/readme.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
Google Apps migration API mail delivery
|
2
|
+
=======================================
|
3
|
+
for Mail Gem
|
4
|
+
------------
|
5
|
+
By Timo van Prooijen
|
6
|
+
- v0.0.1
|
7
|
+
|
8
|
+
|
9
|
+
This gem is extracted, with permission, from a project I'm doing for one of my clients.
|
10
|
+
|
11
|
+
Introduction
|
12
|
+
------------
|
13
|
+
|
14
|
+
'Google Apps migration API mail delivery method' is an extension for the Mail gem. It provides a delivery method based on the the Google Apps migration API. This API is only available for organization who uses Google Apps for Business, Education or ISPs. (unfortunately not for Gmail or the free edition)
|
15
|
+
|
16
|
+
Whenever your application needs to automatically generate *complex* emails, which have to be manually approved before they can get sent out; You can make life easy with this gem in combination with google apps. Instead of delivering the email the email will be stored in a, preconfigured users *DRAFTS* folder. You could also integrate this gem with a CRM system in order to load templates for further manual completion.
|
17
|
+
|
18
|
+
Since this gem uses the Google Apps *migration* API; It is also possible to place messages in the users *SENT* or *INBOX* folder. However a proper use-case hasn't crossed my mind yet. (except for practical jokes)
|
19
|
+
|
20
|
+
Authentication is either done with the credentials of the domain administrator or the user into who's mailbox you are going to migrate.When authenticating as an user, an administrator has to enable the API for that user first. This can be done in the Google Apps control panel for your domain.
|
21
|
+
|
22
|
+
perhaps needless to say: Keep your codebase on a safe place when it contains any plain-text google apps account credentials!
|
23
|
+
|
24
|
+
A possible future extension would be the use of *oAuth* for client authentication. (Useful if the user of your application is also the owner of the account you're *migrating* into )
|
25
|
+
|
26
|
+
|
27
|
+
Example
|
28
|
+
-----
|
29
|
+
|
30
|
+
Gemfile:
|
31
|
+
|
32
|
+
source "http://rubygems.org"
|
33
|
+
gem 'gomig_mail_delivery'
|
34
|
+
|
35
|
+
|
36
|
+
edit example.rb with your domain credentials:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'gomig_mail_delivery'
|
40
|
+
|
41
|
+
Mail.defaults do
|
42
|
+
delivery_method Mail::GomigMailDelivery::Agent, {
|
43
|
+
:domain => '<your domain>.<tld>',
|
44
|
+
:login_account => '<admin_or_user_acount>',
|
45
|
+
:password => '<passwordD>',
|
46
|
+
:to_account => '<target_account>',
|
47
|
+
:mail_item_property => 'IS_DRAFT' # optional. other options: IS_INBOX, IS_SENT
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
mail = Mail.deliver do
|
52
|
+
from 'sender@domain.tld'
|
53
|
+
date Time.now
|
54
|
+
to 'recipient name <recipient@domain.tld>'
|
55
|
+
subject 'I\'m your draft'
|
56
|
+
body 'Ready to send when you are.'
|
57
|
+
end
|
58
|
+
````
|
59
|
+
|
60
|
+
Ready to run
|
61
|
+
|
62
|
+
`bundle install`
|
63
|
+
|
64
|
+
`bundle exec ruby examble.rb`
|
65
|
+
|
66
|
+
Its nice to try an email with html and inline attachments as well.
|
67
|
+
|
68
|
+
|
69
|
+
Contributing
|
70
|
+
------------
|
71
|
+
All welcome. Please, Fork, extend, raise issues, Give feedback. (Its my first gem)..
|
72
|
+
|
73
|
+
|
74
|
+
Future plans
|
75
|
+
------------
|
76
|
+
- OAuth integration.
|
77
|
+
|
78
|
+
|
79
|
+
See Also
|
80
|
+
--------
|
81
|
+
- [link Mail gem](https://github.com/mikel/mail)
|
82
|
+
- [link API specs](https://developers.google.com/google-apps/email-migration/)
|
83
|
+
|
84
|
+
|
85
|
+
Thanks To
|
86
|
+
---------
|
87
|
+
- [link mail-single_file_delivery](https://github.com/lsiden/mail-single_file_delivery (Partially used as a template ) (Partially used as a template )
|
88
|
+
- [link gdata library](http://code.google.com/p/gdata-ruby-util/ (Dependency used for communication with the Google Apps API)
|
89
|
+
|
90
|
+
Support
|
91
|
+
-------
|
92
|
+
Via GitHub. For inquiries about integration work contact me on timo@ewaza.nl
|
93
|
+
|
94
|
+
|
95
|
+
License
|
96
|
+
-------
|
97
|
+
|
98
|
+
(The MIT License)
|
99
|
+
|
100
|
+
Copyright (c) 2009, 2010, 2011, 2012
|
101
|
+
|
102
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
103
|
+
a copy of this software and associated documentation files (the
|
104
|
+
'Software'), to deal in the Software without restriction, including
|
105
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
106
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
107
|
+
permit persons to whom the Software is furnished to do so, subject to
|
108
|
+
the following conditions:
|
109
|
+
|
110
|
+
The above copyright notice and this permission notice shall be
|
111
|
+
included in all copies or substantial portions of the Software.
|
112
|
+
|
113
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
114
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
115
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
116
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
117
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
118
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
119
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'gdata'
|
4
|
+
require 'mail'
|
5
|
+
require 'gomig_mail_delivery'
|
6
|
+
|
7
|
+
|
8
|
+
describe Mail::GomigMailDelivery::Agent do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@google_mock = double('google_mock')
|
12
|
+
@google_mock.stub(:clientlogin)
|
13
|
+
|
14
|
+
GData::Client::Apps.stub(:new){@google_mock}
|
15
|
+
|
16
|
+
Mail.defaults do
|
17
|
+
delivery_method :smtp, { :address => "localhost",
|
18
|
+
:port => 25,
|
19
|
+
:domain => 'localhost.localdomain',
|
20
|
+
:user_name => nil,
|
21
|
+
:password => nil,
|
22
|
+
:authentication => nil,
|
23
|
+
:enable_starttls_auto => true }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond to #settings() and #settings=()" do
|
28
|
+
subject.should respond_to :settings
|
29
|
+
subject.should respond_to :settings=
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should respond to #deliver!()" do
|
33
|
+
subject.should respond_to :deliver!
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "general usage" do
|
37
|
+
|
38
|
+
it "should send an email to the google api" do
|
39
|
+
pending
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gomig_mail_delivery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Timo van Prooijen, eWaza
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mail
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: gdata
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: "\n Google Apps migration API mail delivery method is an extension for the Mail gem. It provides a delivery method based on the the Google Apps migration API. This API is only available for organization who uses Google Apps for Business, Education or ISPs. (unfortunately not for Gmail or the free edition)\n\n Whenever your application needs to automatically generate complex emails, which have to be manually approved before they can get sent out; You can make life easy with this gem in combination with google apps. Instead of delivering the email the email will be stored in a, preconfigured users DRAFTS folder. \n\n You could also integrate this gem with a CRM system in order to load templates for further manual completion.\n "
|
64
|
+
email:
|
65
|
+
- timo@ewaza.nl
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- Rakefile
|
76
|
+
- example/example.rb
|
77
|
+
- gomig_mail_delivery.gemspec
|
78
|
+
- lib/gomig_mail_delivery.rb
|
79
|
+
- readme.md
|
80
|
+
- spec/gomig_mail_delivery_spec.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: https://github.com/ewaza/gomig-mail-delivery
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.5.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Extension for the Mail gem that provides 'migrating' to a google Apps account
|
115
|
+
test_files:
|
116
|
+
- spec/gomig_mail_delivery_spec.rb
|