send_gmail 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/lib/send_gmail.rb +2 -0
- data/lib/send_gmail/messages.rb +25 -0
- data/lib/send_gmail/objects/mail.rb +26 -1
- data/lib/send_gmail/version.rb +1 -1
- data/send_gmail.gemspec +3 -2
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca24ab038cc7145211ffce266bfaa14b97dc6879
|
4
|
+
data.tar.gz: 5beac1e2a7dd2bd04a636329db26217fdb61d737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a1b5a54cdde59568a6940a8c56b0bf336addbc848a40dd94aa545eb103a912351e2c2d4f4b3888e830f6fe564e140bd63929987c8a055bd8955f93f901f5909
|
7
|
+
data.tar.gz: a93c61945d5ce819f71b79ba6d78c7d83d55df8e7f18760e61fbb210ce29504e1fc34ed1b8e29046a413c76d730644cbe45d6e8fecc54460c8cc50194e23d302
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@ now it features only the acquisition of e-mail. this gem is using gmail api.
|
|
5
5
|
https://developers.google.com/gmail/api/
|
6
6
|
|
7
7
|
## Feature
|
8
|
-
* mail sending
|
9
8
|
* create draft
|
10
9
|
* on/off label
|
11
10
|
* other...
|
@@ -36,6 +35,13 @@ $ client.authorize(credentials_path, client_id, client_secret, scope)
|
|
36
35
|
* client_id, client_sercret is https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
|
37
36
|
* scope is https://developers.google.com/gmail/api/auth/scopes
|
38
37
|
|
38
|
+
### First Time
|
39
|
+
1. browser auto open and login user
|
40
|
+
2. auto write oauth information to credentials_path
|
41
|
+
|
42
|
+
### From second time
|
43
|
+
1. if credentials_path is exist, browser no need to open
|
44
|
+
|
39
45
|
## Incoming mail
|
40
46
|
|
41
47
|
```ruby
|
@@ -57,6 +63,11 @@ $ mail_list = client.mail_list(searching_option)
|
|
57
63
|
}
|
58
64
|
```
|
59
65
|
|
66
|
+
## Outgoing mail
|
67
|
+
```ruby
|
68
|
+
$ client.send_mail(to, subject, msg, from = nil, bcc = nil, cc = nil, user_id = 'me')
|
69
|
+
=> 200
|
70
|
+
```
|
60
71
|
|
61
72
|
## Contributing
|
62
73
|
|
data/lib/send_gmail.rb
CHANGED
@@ -2,12 +2,14 @@ require 'google/api_client'
|
|
2
2
|
require 'send_gmail/version'
|
3
3
|
require 'send_gmail/auth'
|
4
4
|
require 'send_gmail/mail_list'
|
5
|
+
require 'send_gmail/messages'
|
5
6
|
require 'send_gmail/objects/mail'
|
6
7
|
|
7
8
|
module SendGmail
|
8
9
|
class Client
|
9
10
|
include SendGmail::Auth
|
10
11
|
include SendGmail::MailList
|
12
|
+
include SendGmail::Messages
|
11
13
|
|
12
14
|
attr_accessor :authorization, :client, :gmail_api
|
13
15
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SendGmail
|
2
|
+
module Messages
|
3
|
+
def send_mail(to, subject, msg, from = nil, bcc = nil, cc = nil, user_id = 'me')
|
4
|
+
raw_data = SendGmail::Objects::Mail.new(
|
5
|
+
to: to,
|
6
|
+
subject: subject,
|
7
|
+
body: msg,
|
8
|
+
from: from,
|
9
|
+
bcc: bcc,
|
10
|
+
cc: cc
|
11
|
+
).to_raw_data
|
12
|
+
|
13
|
+
parameters = { userId: user_id }
|
14
|
+
|
15
|
+
result = @client.execute!(
|
16
|
+
api_method: @gmail_api.users.messages.to_h['gmail.users.messages.send'],
|
17
|
+
parameters: parameters,
|
18
|
+
body_object: {
|
19
|
+
raw: Base64.urlsafe_encode64(raw_data)
|
20
|
+
}
|
21
|
+
)
|
22
|
+
result.status
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,7 +1,32 @@
|
|
1
|
+
require 'mail'
|
1
2
|
module SendGmail
|
2
3
|
module Objects
|
3
4
|
class Mail
|
4
|
-
attr_accessor :subject, :from, :date, :body
|
5
|
+
attr_accessor :subject, :from, :date, :body, :bcc, :to, :cc
|
6
|
+
|
7
|
+
def initialize(params = {})
|
8
|
+
params.each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_raw_data
|
14
|
+
msg = body.to_s
|
15
|
+
from_text = from
|
16
|
+
to_text = to
|
17
|
+
subject_text = subject
|
18
|
+
|
19
|
+
mail = ::Mail.new do
|
20
|
+
from from_text
|
21
|
+
to to_text
|
22
|
+
subject subject_text
|
23
|
+
body msg
|
24
|
+
end
|
25
|
+
raw = mail.to_s
|
26
|
+
raw = "Bcc:#{bcc}\r\n#{raw}" unless bcc.nil?
|
27
|
+
raw = "Cc:#{cc}\r\n#{raw}" unless cc.nil?
|
28
|
+
raw
|
29
|
+
end
|
5
30
|
end
|
6
31
|
end
|
7
32
|
end
|
data/lib/send_gmail/version.rb
CHANGED
data/send_gmail.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['hatappi']
|
10
10
|
spec.email = ['hata.yusaku.1225@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = 'incoming mail'
|
13
|
-
spec.description = 'incoming mail by google gmail api'
|
12
|
+
spec.summary = 'incoming, outgoing mail'
|
13
|
+
spec.description = 'incoming, outgoing mail by google gmail api'
|
14
14
|
spec.homepage = 'https://github.com/hatappi/send_gmail'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
30
30
|
spec.add_development_dependency 'rspec'
|
31
31
|
spec.add_development_dependency 'google-api-client'
|
32
|
+
spec.add_development_dependency 'mail'
|
32
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: send_gmail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hatappi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,21 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mail
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: incoming, outgoing mail by google gmail api
|
70
84
|
email:
|
71
85
|
- hata.yusaku.1225@gmail.com
|
72
86
|
executables:
|
@@ -88,6 +102,7 @@ files:
|
|
88
102
|
- lib/send_gmail.rb
|
89
103
|
- lib/send_gmail/auth.rb
|
90
104
|
- lib/send_gmail/mail_list.rb
|
105
|
+
- lib/send_gmail/messages.rb
|
91
106
|
- lib/send_gmail/objects/mail.rb
|
92
107
|
- lib/send_gmail/version.rb
|
93
108
|
- send_gmail.gemspec
|
@@ -115,5 +130,5 @@ rubyforge_project:
|
|
115
130
|
rubygems_version: 2.4.5.1
|
116
131
|
signing_key:
|
117
132
|
specification_version: 4
|
118
|
-
summary: incoming mail
|
133
|
+
summary: incoming, outgoing mail
|
119
134
|
test_files: []
|