gmail-mailer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/gmail-mailer.gemspec +59 -0
- data/lib/gmail-mailer.rb +64 -0
- metadata +134 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
|
+
gem "mail","~> 2.2.13"
|
12
|
+
gem "gmail_xoauth", "~> 0.3.0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.3)
|
5
|
+
git (1.2.5)
|
6
|
+
gmail_xoauth (0.3.0)
|
7
|
+
oauth (>= 0.3.6)
|
8
|
+
i18n (0.5.0)
|
9
|
+
jeweler (1.5.2)
|
10
|
+
bundler (~> 1.0.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
mail (2.2.13)
|
14
|
+
activesupport (>= 2.3.6)
|
15
|
+
i18n (>= 0.4.0)
|
16
|
+
mime-types (~> 1.16)
|
17
|
+
treetop (~> 1.4.8)
|
18
|
+
mime-types (1.16)
|
19
|
+
oauth (0.4.4)
|
20
|
+
polyglot (0.3.1)
|
21
|
+
rake (0.8.7)
|
22
|
+
treetop (1.4.9)
|
23
|
+
polyglot (>= 0.3.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
gmail_xoauth (~> 0.3.0)
|
31
|
+
jeweler (~> 1.5.2)
|
32
|
+
mail (~> 2.2.13)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Daniel Harper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= gmail-mailer
|
2
|
+
|
3
|
+
simple gem to allow you to send emails using your gmail account (without having to fiddle around with passwords)
|
4
|
+
|
5
|
+
== Contributing to gmail-mailer
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Daniel Harper. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "gmail-mailer"
|
16
|
+
gem.homepage = "http://github.com/djhworld/gmail-mailer"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Send emails using a your gmail account (via OAUTH)}
|
19
|
+
gem.description = %Q{Programatically send emails using a given gmail account. No username/passwords needed, just use your OAUTH credentials}
|
20
|
+
gem.email = "djharperuk@gmail.com"
|
21
|
+
gem.authors = ["Daniel Harper"]
|
22
|
+
end
|
23
|
+
Jeweler::RubygemsDotOrgTasks.new
|
24
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{gmail-mailer}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Daniel Harper"]
|
12
|
+
s.date = %q{2011-01-09}
|
13
|
+
s.description = %q{Programatically send emails using a given gmail account. No username/passwords needed, just use your OAUTH credentials}
|
14
|
+
s.email = %q{djharperuk@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"gmail-mailer-0.1.0.gem",
|
28
|
+
"gmail-mailer.gemspec",
|
29
|
+
"lib/gmail-mailer.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/djhworld/gmail-mailer}
|
32
|
+
s.licenses = ["MIT"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.7}
|
35
|
+
s.summary = %q{Send emails using a your gmail account (via OAUTH)}
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
43
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
44
|
+
s.add_development_dependency(%q<mail>, ["~> 2.2.13"])
|
45
|
+
s.add_development_dependency(%q<gmail_xoauth>, ["~> 0.3.0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
49
|
+
s.add_dependency(%q<mail>, ["~> 2.2.13"])
|
50
|
+
s.add_dependency(%q<gmail_xoauth>, ["~> 0.3.0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_dependency(%q<mail>, ["~> 2.2.13"])
|
56
|
+
s.add_dependency(%q<gmail_xoauth>, ["~> 0.3.0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/lib/gmail-mailer.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'mail'
|
2
|
+
require 'gmail_xoauth'
|
3
|
+
module GmailMailer
|
4
|
+
class Mailer
|
5
|
+
def initialize(credentials)
|
6
|
+
raise ArgumentError if !validate_credentials(credentials)
|
7
|
+
@email_credentials = credentials
|
8
|
+
end
|
9
|
+
|
10
|
+
def sendMessage(message)
|
11
|
+
mail = Mail.new do
|
12
|
+
from message.from
|
13
|
+
to message.to
|
14
|
+
subject message.subject
|
15
|
+
body message.body
|
16
|
+
if(message.attachment != nil)
|
17
|
+
add_file message.attachment
|
18
|
+
end
|
19
|
+
end
|
20
|
+
sendSMTP(mail)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Use gmail_xoauth to send email
|
24
|
+
def sendSMTP(mail)
|
25
|
+
smtp = Net::SMTP.new(@email_credentials[:smtp_server], @email_credentials[:smtp_port])
|
26
|
+
smtp.enable_starttls_auto
|
27
|
+
secret = {
|
28
|
+
:consumer_key => @email_credentials[:smtp_consumer_key],
|
29
|
+
:consumer_secret => @email_credentials[:smtp_consumer_secret],
|
30
|
+
:token => @email_credentials[:smtp_oauth_token],
|
31
|
+
:token_secret => @email_credentials[:smtp_oauth_token_secret]
|
32
|
+
}
|
33
|
+
smtp.start(@email_credentials[:host], @email_credentials[:email], secret, :xoauth) do |session|
|
34
|
+
print "Sending message..."
|
35
|
+
session.send_message(mail.encoded, mail.from_addrs.first, mail.destinations)
|
36
|
+
puts ".sent!"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_credentials(creds)
|
41
|
+
false if creds.nil?
|
42
|
+
false if !creds.key?:smtp_server or creds[:smtp_server].nil?
|
43
|
+
false if !creds.key?:smtp_port or creds[:smtp_port].nil?
|
44
|
+
false if !creds.key?:smtp_consumer_key or creds[:smtp_consumer_key].nil?
|
45
|
+
false if !creds.key?:smtp_consumer_secret or creds[:smtp_consumer_secret].nil?
|
46
|
+
false if !creds.key?:smtp_oauth_token or creds[:smtp_oauth_token].nil?
|
47
|
+
false if !creds.key?:smtp_oauth_token_secret or creds[:smtp_oauth_token_secret].nil?
|
48
|
+
false if !creds.key?:host or creds[:host].nil?
|
49
|
+
false if !creds.key?:email or creds[:email].nil?
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Message
|
55
|
+
attr_reader :to, :from, :subject, :body, :attachment
|
56
|
+
def initialize(to, from, attachment=nil, subject="", body="")
|
57
|
+
@to = to
|
58
|
+
@from = from
|
59
|
+
@subject = subject
|
60
|
+
@body = body
|
61
|
+
@attachment = attachment
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmail-mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Daniel Harper
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-09 00:00:00 +00:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeweler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 5
|
45
|
+
- 2
|
46
|
+
version: 1.5.2
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: mail
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 2
|
60
|
+
- 13
|
61
|
+
version: 2.2.13
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: gmail_xoauth
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
- 3
|
75
|
+
- 0
|
76
|
+
version: 0.3.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
description: Programatically send emails using a given gmail account. No username/passwords needed, just use your OAUTH credentials
|
81
|
+
email: djharperuk@gmail.com
|
82
|
+
executables: []
|
83
|
+
|
84
|
+
extensions: []
|
85
|
+
|
86
|
+
extra_rdoc_files:
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.rdoc
|
89
|
+
files:
|
90
|
+
- .document
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.rdoc
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- gmail-mailer-0.1.0.gem
|
98
|
+
- gmail-mailer.gemspec
|
99
|
+
- lib/gmail-mailer.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/djhworld/gmail-mailer
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: -3309278074508641666
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.3.7
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Send emails using a your gmail account (via OAUTH)
|
133
|
+
test_files: []
|
134
|
+
|