gmail_sender 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/VERSION +1 -1
- data/bin/gmail +3 -4
- data/gmail_sender.gemspec +2 -2
- data/lib/gmail_sender.rb +4 -5
- data/lib/gmail_sender/message_stream_writer.rb +2 -1
- data/lib/gmail_sender/utils.rb +4 -2
- data/test/gmail_sender_test.rb +6 -0
- data/test/message_stream_writer_test.rb +7 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -9,6 +9,7 @@ A simple gem to send email through gmail
|
|
9
9
|
g.attach('/path/to/document.hz') # you can attach any number of files, but there are limits for total attachments size
|
10
10
|
g.send(:to => "someone@domain.com", :subject => "The subject", :content => "The mail body")
|
11
11
|
|
12
|
+
Notice that the ':to' key accepts an email array so you can send the message to many receivers.
|
12
13
|
You can specify the content type which is text/plain by default.
|
13
14
|
|
14
15
|
g.send(:to => "someone@domain.com",
|
@@ -38,7 +39,7 @@ To send your directory list to the default receiver:
|
|
38
39
|
|
39
40
|
You can specify some parameters like in this example which doesn't use pipes:
|
40
41
|
|
41
|
-
gmail -t somebody@gmail.com -s "This is the subject" -c "This is the email content"
|
42
|
+
gmail -t somebody@gmail.com someoneelse@hotmail.com -s "This is the subject" -c "This is the email content"
|
42
43
|
|
43
44
|
You can send attachments by using the -a option (this example assumes that you have a receiver_email set in the ~/.gmail file so the -t is not needed):
|
44
45
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/bin/gmail
CHANGED
@@ -10,8 +10,8 @@ Choice.options do
|
|
10
10
|
|
11
11
|
option :receiver_email do
|
12
12
|
short '-t'
|
13
|
-
long '--to
|
14
|
-
desc '
|
13
|
+
long '--to=*RECEIVERS'
|
14
|
+
desc 'A list of space separated receiver emails'
|
15
15
|
end
|
16
16
|
|
17
17
|
option :subject do
|
@@ -32,12 +32,11 @@ Choice.options do
|
|
32
32
|
desc 'Content Type, text/plain by default, use text/html for html'
|
33
33
|
end
|
34
34
|
|
35
|
-
option :attachments do
|
35
|
+
option :attachments do
|
36
36
|
short '-a'
|
37
37
|
long '--attachments *ATTACHMENTS'
|
38
38
|
desc "A list of space separated list of files you wish to attach."
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
41
|
|
43
42
|
def params
|
data/gmail_sender.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gmail_sender}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Cadenas"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-12}
|
13
13
|
s.default_executable = %q{gmail}
|
14
14
|
s.email = %q{dcadenas@gmail.com}
|
15
15
|
s.executables = ["gmail"]
|
data/lib/gmail_sender.rb
CHANGED
@@ -21,16 +21,15 @@ class GmailSender
|
|
21
21
|
@message_stream_writer.attachments << file if File.exist?(file)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
to
|
24
|
+
def send(options = {})
|
25
|
+
raise(Error, "Missing receiver (:to => 'someone@somehost.com')") if Utils.blank?(options[:to])
|
26
|
+
to = [options[:to]].flatten
|
26
27
|
subject = options[:subject] || ""
|
27
28
|
content = options[:content] || ""
|
28
29
|
content_type = options[:content_type] || "text/plain; charset='utf-8'"
|
29
30
|
|
30
|
-
raise(Error, "Missing receiver (:to => 'someone@somehost.com')") if Utils.blank?(to)
|
31
|
-
|
32
31
|
@net_smtp.start(@sender_domain, @sender_email, @sender_password, :plain) do |smtp|
|
33
|
-
smtp.open_message_stream(@sender_email,
|
32
|
+
smtp.open_message_stream(@sender_email, to) do |msg_stream|
|
34
33
|
@message_stream_writer.write(msg_stream, to, subject, content, content_type)
|
35
34
|
end
|
36
35
|
end
|
@@ -19,11 +19,12 @@ class GmailSender
|
|
19
19
|
private
|
20
20
|
def write_headers(msg_stream, to, subject)
|
21
21
|
msg_stream.puts "From: #{@sender_email}"
|
22
|
+
to = to.join(",") if to.respond_to?(:join)
|
22
23
|
msg_stream.puts "To: #{to}"
|
23
24
|
msg_stream.puts "Subject: #{subject}"
|
24
25
|
msg_stream.puts 'MIME-Version: 1.0'
|
25
26
|
unless @attachments.empty?
|
26
|
-
|
27
|
+
msg_stream.puts %{Content-Type: multipart/mixed; boundary="#{@boundary}"}
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
data/lib/gmail_sender/utils.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
class GmailSender
|
2
2
|
module Utils
|
3
|
-
def self.blank?(
|
4
|
-
|
3
|
+
def self.blank?(string_or_array)
|
4
|
+
string_or_array.nil? ||
|
5
|
+
string_or_array.respond_to?(:strip) && string_or_array.strip == "" ||
|
6
|
+
string_or_array.respond_to?(:empty?) && string_or_array.empty?
|
5
7
|
end
|
6
8
|
end
|
7
9
|
end
|
data/test/gmail_sender_test.rb
CHANGED
@@ -35,6 +35,12 @@ Expectations do
|
|
35
35
|
FakedNetSMTP.sent_email
|
36
36
|
end
|
37
37
|
|
38
|
+
expect "From: me@somehost.com\nTo: someone@someotherhost.com,someone2@someotherhost.com\nSubject: hi!\nMIME-Version: 1.0\nContent-Type: text/plain; charset='utf-8'\n\nho\n" do
|
39
|
+
gmail_sender = GmailSender.new("me@somehost.com", "password", FakedNetSMTP)
|
40
|
+
gmail_sender.send(:to => ["someone@someotherhost.com", "someone2@someotherhost.com"], :subject => "hi!", :content => "ho")
|
41
|
+
FakedNetSMTP.sent_email
|
42
|
+
end
|
43
|
+
|
38
44
|
expect GmailSender::Error do
|
39
45
|
gmail_sender = GmailSender.new("me@somehost.com", "password", FakedNetSMTP)
|
40
46
|
gmail_sender.send(:subject => "hi!", :content => "ho")
|
@@ -8,6 +8,13 @@ Expectations do
|
|
8
8
|
string_io.string
|
9
9
|
end
|
10
10
|
|
11
|
+
expect "From: sender@gmail.com\nTo: to@gmail.com,to2@gmail.com\nSubject: subject\nMIME-Version: 1.0\nContent-Type: text/plain\n\nbody\n" do
|
12
|
+
string_io = StringIO.new
|
13
|
+
message_stream_writer = GmailSender::MessageStreamWriter.new("sender@gmail.com")
|
14
|
+
message_stream_writer.write(string_io, ["to@gmail.com", "to2@gmail.com"], "subject", "body", "text/plain")
|
15
|
+
string_io.string
|
16
|
+
end
|
17
|
+
|
11
18
|
expect eval(<<-MAIL_WITH_ATTACHMENT_REGEXP) do
|
12
19
|
/From: sender@gmail.com
|
13
20
|
To: to@gmail.com
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Cadenas
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-12 00:00:00 -03:00
|
18
18
|
default_executable: gmail
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|