gmail_sender 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,10 +8,31 @@ A simple gem to send email through gmail
8
8
  g = GmailSender.new("gmail_account_user_name", "gmail_account_password")
9
9
  g.send("someone@domain.com", "The subject", "The mail body")
10
10
 
11
+ == Command line usage
12
+
13
+ You can also use gmail_sender from the command line. First you need to create ~/.gmail with this content (YAML):
14
+
15
+ receiver_email: default_receiver@gmail.com
16
+ sender_user: gmail_account_user_name
17
+ sender_password: gmail_account_password
18
+
19
+ Is advisable to use a different sender account than your main email address so that it's not so bad if someone reads your configuration file and gets your password.
20
+
21
+ === Examples
22
+
23
+ To send your directory list to the default receiver:
24
+
25
+ ls | gmail
26
+
27
+ You can specify some parameters like in this example which doesn't use pipes:
28
+
29
+ gmail -t somebody@gmail.com -s "This is the subject" -c "This is the email content"
30
+
11
31
  == Requirements
12
32
 
13
33
  tlsmail if running Ruby 1.8.6
14
34
 
15
- == Copyright
35
+ == Major contributors
16
36
 
17
- Copyright (c) 2009 Daniel Cadenas. See LICENSE for details.
37
+ * Daniel Cadenas - Maintainer
38
+ * Felipe Coury
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/gmail ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gmail_sender'
5
+ require 'choice'
6
+
7
+ Choice.options do
8
+ header ''
9
+ header 'options:'
10
+
11
+ option :receiver_email do
12
+ short '-t'
13
+ long '--to=RECEIVER'
14
+ desc 'Receiver of the email'
15
+ end
16
+
17
+ option :subject do
18
+ short '-s'
19
+ long '--subject=SUBJECT'
20
+ desc 'Subject of the email'
21
+ end
22
+
23
+ option :content do
24
+ short '-c'
25
+ long '--content=MAIL_CONTENTS'
26
+ desc 'Body of the email, uses STDIN if omitted'
27
+ end
28
+ end
29
+
30
+ def params
31
+ return @params if @params
32
+
33
+ config_file_path = File.join(ENV['HOME'],'.gmail')
34
+ if !File.exists?(config_file_path)
35
+ STDERR.puts "Please first create a ~/.gmail file with some defaults. Example:
36
+ receiver_email: default_receiver@gmail.com
37
+ sender_user: gmail_account_user_name
38
+ sender_password: gmail_account_user_password
39
+ "
40
+ exit 1
41
+ end
42
+
43
+ defaults = {'subject' => 'Sent from command line',
44
+ 'sender_domain' => 'gmail.com'}
45
+
46
+ @params = defaults.merge(YAML.load_file(config_file_path)).merge(Choice.choices)
47
+ end
48
+
49
+
50
+ mailer = GmailSender.new(params['sender_user'], params['sender_password'], params['sender_domain'])
51
+ mailer.send(params['receiver_email'], params['subject'], params['content'] || STDIN.read)
data/gmail_sender.gemspec CHANGED
@@ -2,15 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gmail_sender}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Daniel Cadenas"]
8
+ s.authors = ["Daniel Cadenas", "Felipe Coury"]
9
9
  s.date = %q{2009-05-25}
10
- s.email = %q{dcadenas@gmail.com}
10
+ s.email = %q{dcadenas@gmail.com felipe.coury@gmail.com}
11
+ s.bindir = "bin"
12
+ s.executables = ["gmail"]
11
13
  s.extra_rdoc_files = [
12
14
  "LICENSE",
13
- "README.rdoc"
15
+ "README.rdoc"
14
16
  ]
15
17
  s.files = [
16
18
  ".document",
@@ -20,6 +22,7 @@ Gem::Specification.new do |s|
20
22
  "Rakefile",
21
23
  "VERSION",
22
24
  "gmail_sender.gemspec",
25
+ "bin/gmail",
23
26
  "lib/gmail_sender.rb",
24
27
  "lib/tls_smtp_patch.rb",
25
28
  "test/gmail_sender_test.rb",
@@ -29,7 +32,7 @@ Gem::Specification.new do |s|
29
32
  s.rdoc_options = ["--charset=UTF-8"]
30
33
  s.require_paths = ["lib"]
31
34
  s.rubygems_version = %q{1.3.3}
32
- s.summary = %q{A simple gem to send email through gmail}
35
+ s.summary = s.description = %q{A simple gem to send email through gmail}
33
36
  s.test_files = [
34
37
  "test/gmail_sender_test.rb",
35
38
  "test/test_helper.rb"
@@ -40,6 +43,7 @@ Gem::Specification.new do |s|
40
43
  s.specification_version = 3
41
44
 
42
45
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<choice>, [">= 0"])
43
47
  else
44
48
  end
45
49
  else
data/lib/gmail_sender.rb CHANGED
@@ -1,23 +1,24 @@
1
1
  require "tls_smtp_patch"
2
2
 
3
3
  class GmailSender
4
- def initialize(gmail_user, gmail_password)
5
- @gmail_user = "#{gmail_user}@gmail.com"
6
- @gmail_password = gmail_password
4
+ def initialize(user, password, domain="gmail.com")
5
+ @sender_domain = domain
6
+ @sender_password = password
7
+ @sender_email = "#{user}@#{domain}"
7
8
  @net_smtp = Net::SMTP.new("smtp.gmail.com", 587)
8
9
  @net_smtp.enable_starttls
9
10
  end
10
11
 
11
12
  def send(to, subject, content)
12
- @net_smtp.start("gmail.com", @gmail_user, @gmail_password, :plain) do |smtp|
13
+ @net_smtp.start(@sender_domain, @sender_email, @sender_password, :plain) do |smtp|
13
14
  msg = create_message(to, subject, content)
14
- smtp.send_message(msg, @gmail_user, to)
15
+ smtp.send_message(msg, @sender_email, to)
15
16
  end
16
17
  end
17
18
 
18
19
  def create_message(to, subject, content)
19
20
  <<MSG
20
- From: #@gmail_user
21
+ From: #@sender_email
21
22
  To: #{to}
22
23
  Subject: #{subject}
23
24
 
@@ -25,4 +26,3 @@ Subject: #{subject}
25
26
  MSG
26
27
  end
27
28
  end
28
-
@@ -1,6 +1,6 @@
1
1
  require "net/smtp"
2
2
 
3
- if !Net::SMTP.instance_methods.include?(:enable_starttls)
3
+ unless Net::SMTP.instance_methods.include?(:enable_starttls)
4
4
  require "tlsmail"
5
5
  class Net::SMTP
6
6
  def enable_starttls
data/test/test_helper.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'expectations'
3
3
 
4
-
5
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
6
  require 'gmail_sender'
8
-
9
- class Test::Unit::TestCase
10
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmail_sender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Cadenas
@@ -9,14 +9,14 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-25 00:00:00 -03:00
13
- default_executable:
12
+ date: 2009-11-02 00:00:00 -02:00
13
+ default_executable: gmail
14
14
  dependencies: []
15
15
 
16
16
  description:
17
17
  email: dcadenas@gmail.com
18
- executables: []
19
-
18
+ executables:
19
+ - gmail
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
@@ -29,6 +29,7 @@ files:
29
29
  - README.rdoc
30
30
  - Rakefile
31
31
  - VERSION
32
+ - bin/gmail
32
33
  - gmail_sender.gemspec
33
34
  - lib/gmail_sender.rb
34
35
  - lib/tls_smtp_patch.rb
@@ -58,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
59
  requirements: []
59
60
 
60
61
  rubyforge_project:
61
- rubygems_version: 1.3.3
62
+ rubygems_version: 1.3.5
62
63
  signing_key:
63
64
  specification_version: 3
64
65
  summary: A simple gem to send email through gmail