ez-email 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5271a5ec723de38f562e97cc2f49e3f30d9f230072856fc2820d9bffe72ff80
4
+ data.tar.gz: e8c8a28d1e6e8975fd1b9347f3ca8788b780eaac392d506c205d8103c8ab73dd
5
+ SHA512:
6
+ metadata.gz: b81042453b535a6f0313ac46cc4bc248a625f97b3de5330420a9b58f6cde505bf817750144e4fa7642bcebbd23463696d846edc0ae75964d1da9cd32b062762f
7
+ data.tar.gz: 696fe533fd9ae5621a4a9162716afa5de920a6acf6c56afa5c388be3189bd3ea490de905508722016b4979fa218542cc4ca0456e33b50795c26503aa81c40000
Binary file
@@ -0,0 +1 @@
1
+ ��1�2h���P�Y#�oKi+���������@_����4xNg�}� ��/oѠ���A�<�JQ���{ >y^��u"l�=Ĥ�_��F�WD��)Ѳt�3*z���D����ʄ1������I��|RZ�6�KZ%�a��D�E��xc,1;��d�1na{��� �$!縓f��������o@�@�]�D��{��H����P���(l�bf^����Q6y��T�I�{���Zu8xh�š�kP��Dh�������gf�SJ㽫p)|qd ��[���f�������� ����^H��N��^d�K�Ȓ���rcR��-v�!A����k�ʏ��)c�֓�0�� bFW��-�D����[^M'#r(��,�6��p��î��
data/CHANGES CHANGED
@@ -1,3 +1,27 @@
1
+ == 0.2.1 - 1-Jun-2020
2
+ * Added a LICENSE file to the distro as required by the Apache-2.0 license.
3
+
4
+ == 0.2.0 - 28-Jan-2019
5
+ * Changed license to Apache-2.0.
6
+ * Fixed a bug where it was blowing up on a single "to" argument.
7
+ * The VERSION constant is now frozen.
8
+ * Added the ez-mail.rb file for convenience.
9
+ * Modified code internally to use singletons instead of class variables.
10
+ * Updated cert, should be good for about 10 years.
11
+ * Added metadata to the gemspec.
12
+
13
+ == 0.1.5 - 12-Dec-2015
14
+ * This gem is now signed.
15
+ * Updates to Rakefile and gemspec for gem signing.
16
+
17
+ == 0.1.4 - 8-Nov-2014
18
+ * Minor updates to gemspec and Rakefile.
19
+
20
+ == 0.1.3 - 9-Jan-2013
21
+ * Fixed a bug where the default 'from' value was not actually being set
22
+ if it wasn't explicitly specified.
23
+ * Refactored the tests and use test-unit 2 instead.
24
+
1
25
  == 0.1.2 - 31-Aug-2011
2
26
  * Refactored the Rakefile. Removed the old install task, added a clean
3
27
  task, added a default task, and reorganized the gem tasks.
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
data/MANIFEST CHANGED
@@ -1,6 +1,10 @@
1
1
  * CHANGES
2
+ * LICENSE
2
3
  * MANIFEST
4
+ * README
3
5
  * Rakefile
4
6
  * ez-email.gemspec
7
+ * certs/djberg96_pub.pem
8
+ * lib/ez-email.rb
5
9
  * lib/ez/email.rb
6
- * test/test_ez_email.rb
10
+ * test/test_ez_email.rb
data/README CHANGED
@@ -5,32 +5,32 @@
5
5
  gem install ez-email
6
6
 
7
7
  = Synopsis
8
- require 'ez/email'
8
+ require 'ez-email'
9
9
 
10
10
  EZ::Email.deliver(
11
- :to => 'your_friend@hotstuff.com',
12
- :from => 'you@blah.com',
13
- :subject => 'Hello',
14
- :body => 'How are you?'
11
+ :to => 'your_friend@hotstuff.com',
12
+ :from => 'you@blah.com',
13
+ :subject => 'Hello',
14
+ :body => 'How are you?'
15
15
  )
16
16
 
17
17
  = Rationale
18
- The present batch of email handling libraries are either not designed
19
- for sending email, or are extremely cumbersome, have lousy interfaces,
20
- or are no longer maintained.
18
+ When I originally created this library the existing list of email handling
19
+ libraries were either not designed for sending email, were extremely cumbersome,
20
+ had lousy interfaces, or were no longer maintained.
21
21
 
22
- I just want to sent a flippin' email! This library scratched that itch.
22
+ I just wanted to send a flippin' email! This library scratched that itch.
23
23
  Hopefully you will find its simplicity useful, too.
24
24
 
25
25
  = Bugs
26
26
  None that I'm aware of. Please log any bug reports on the project page at
27
- http://www.rubyforge.org/projects/shards.
27
+ https://github.com/djberg96/ez-email.
28
28
 
29
29
  = License
30
- Artistic 2.0
30
+ Apache-2.0
31
31
 
32
32
  = Copyright
33
- (C) 2009-2011, Daniel J. Berger, All Rights Reserved
33
+ (C) 2009-2019, Daniel J. Berger, All Rights Reserved
34
34
 
35
35
  = Author
36
36
  Daniel Berger
data/Rakefile CHANGED
@@ -7,14 +7,16 @@ CLEAN.include("**/*.gem", "**/*.rbc")
7
7
  namespace :gem do
8
8
  desc 'Build the ez-email gem'
9
9
  task :create => [:clean] do
10
+ require 'rubygems/package'
10
11
  spec = eval(IO.read('ez-email.gemspec'))
11
- Gem::Builder.new(spec).build
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec, true)
12
14
  end
13
15
 
14
16
  desc "Install the ez-email package as a gem"
15
17
  task :install => [:create] do
16
18
  file = Dir["*.gem"].first
17
- sh "gem install #{file}"
19
+ sh "gem install -l #{file}"
18
20
  end
19
21
  end
20
22
 
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
10
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
11
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
12
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
13
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
14
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
15
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
16
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
17
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
18
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
19
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
20
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
21
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
22
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
23
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
24
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
25
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
26
+ -----END CERTIFICATE-----
@@ -1,17 +1,28 @@
1
1
  require 'rubygems'
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = 'ez-email'
5
- s.version = '0.1.2'
6
- s.license = 'Artistic 2.0'
7
- s.summary = 'Really easy emails'
8
- s.description = 'A very simple interface for sending email'
9
- s.author = 'Daniel Berger'
10
- s.email = 'djberg96@gmail.com'
11
- s.homepage = 'http://www.rubyforge.org/projects/shards'
12
- s.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
- s.test_file = 'test/test_ez_email.rb'
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'ez-email'
5
+ spec.version = '0.2.1'
6
+ spec.license = 'Apache-2.0'
7
+ spec.summary = 'Really easy emails'
8
+ spec.description = 'A very simple interface for sending email'
9
+ spec.author = 'Daniel Berger'
10
+ spec.email = 'djberg96@gmail.com'
11
+ spec.homepage = 'https://github.com/djberg96/ez-email'
12
+ spec.test_file = 'test/test_ez_email.rb'
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
+ spec.cert_chain = Dir['certs/*']
14
15
 
15
- s.rubyforge_project = 'shards'
16
- s.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
16
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
17
+
18
+ spec.add_development_dependency('test-unit')
19
+
20
+ spec.metadata = {
21
+ 'homepage_uri' => 'https://github.com/djberg96/ez-email',
22
+ 'bug_tracker_uri' => 'https://github.com/djberg96/ez-email/issues',
23
+ 'changelog_uri' => 'https://github.com/djberg96/ez-email/blob/master/CHANGES',
24
+ 'documentation_uri' => 'https://github.com/djberg96/ez-email/wiki',
25
+ 'source_code_uri' => 'https://github.com/djberg96/ez-email',
26
+ 'wiki_uri' => 'https://github.com/djberg96/ez-email/wiki'
27
+ }
17
28
  end
@@ -0,0 +1 @@
1
+ require_relative 'ez/email'
@@ -5,138 +5,128 @@ require 'net/smtp'
5
5
 
6
6
  # The EZ module serves as a namespace only.
7
7
  module EZ
8
-
9
- # The Email class encapsulates certain SMTP attributes, which are then
10
- # used to send simple emails.
11
- class Email
12
- # The version of the ez-email library
13
- VERSION = '0.1.2'
14
-
15
- begin
16
- @@mail_host = Resolv.getaddress('mailhost')
17
- rescue Resolv::ResolvError
18
- @@mail_host = 'localhost'
19
- end
20
8
 
21
- @@mail_port = 25
22
-
9
+ # The Email class encapsulates certain SMTP attributes, which are then
10
+ # used to send simple emails.
11
+ class Email
12
+ # The version of the ez-email library
13
+ VERSION = '0.2.1'.freeze
14
+
15
+ class << self
16
+ attr_writer :mail_host
17
+ attr_writer :mail_port
18
+
23
19
  # The name of the mail host to use when sending email. The default
24
20
  # is whatever the address of your system's 'mailhost' resolves to.
25
21
  # If that cannot be determined, your localhost is used.
26
22
  #
27
- def self.mail_host
28
- @@mail_host
29
- end
30
-
31
- # Sets the mail host.
32
- def self.mail_host=(host)
33
- @@mail_host = host
23
+ def mail_host
24
+ @mail_host ||= Resolv.getaddress('mailhost')
25
+ rescue Resolv::ResolvError
26
+ @mail_host ||= 'localhost'
34
27
  end
35
-
28
+
36
29
  # The port to use when sending email. The default is 25.
37
- def self.mail_port
38
- @@mail_port
39
- end
40
-
41
- # Sets the mail port.
42
- def self.mail_port=(port)
43
- @@mail_port = 25
44
- end
45
-
46
- # A single email address or an array of email addresses to whom
47
- # the email should be sent. Mandatory.
48
- attr_accessor :to
49
-
50
- # A single email address from whom the email is being delivered. The
51
- # default is your login + '@' + your host name, though it is recommended
52
- # that you specify it explicitly.
53
- attr_accessor :from
54
-
55
- # The subject of the email. Mandatory.
56
- attr_accessor :subject
57
-
58
- # The body of the email. Mandatory.
59
- attr_accessor :body
60
-
61
- # Creates a new EZ::Email object. As a general rule you won't use
62
- # this method, but should use EZ::Email.deliver instead.
63
- #
64
- def initialize(options={})
65
- raise TypeError unless options.is_a?(Hash)
66
- validate_options(options)
67
- @options = options
68
- end
69
-
70
- # Sends the email based on the options passed to the constructor.
71
- # As a general rule you won't use this method directly, but should
72
- # use EZ::Email.deliver instead.
73
30
  #
74
- def deliver
75
- host = EZ::Email.mail_host
76
- port = EZ::Email.mail_port
77
-
78
- Net::SMTP.start(host, port, host){ |smtp|
79
- smtp.open_message_stream(self.from, self.to){ |stream|
80
- stream.puts "From: #{self.from}"
81
- stream.puts "To: " + self.to.to_a.join(', ')
82
- stream.puts "Subject: #{self.subject}"
83
- stream.puts
84
- stream.puts self.body
85
- }
86
- }
31
+ def mail_port
32
+ @mail_port ||= 25
87
33
  end
34
+ end
88
35
 
89
- # Delivers a simple text email message using four options:
90
- #
91
- # * to
92
- # * from
93
- # * subject
94
- # * body
95
- #
96
- # Examples:
97
- #
98
- # # Send an email to a single user
99
- # EZ::Email.deliver(
100
- # :to => 'some_user@hotmail.com',
101
- # :from => 'me@hotmail.com',
102
- # :subject => 'Hi',
103
- # :body => 'How are you?'
104
- # )
105
- #
106
- # # Send an email to a multiple users
107
- # EZ::Email.deliver(
108
- # :to => ['jon@hotmail.com', 'mary@hotmail.com'],
109
- # :from => 'me@hotmail.com',
110
- # :subject => 'Hi',
111
- # :body => 'How are you?'
112
- # )
113
- #
114
- # This is a shortcut for EZ::Email.new + EZ::Email#deliver.
115
- #
116
- def self.deliver(options)
117
- new(options).deliver
118
- end
119
-
120
- private
121
-
122
- # Private method that both validates the hash options, and sets
123
- # the attribute values.
124
- #
125
- def validate_options(hash)
126
- valid = %w/to from subject body/
127
- hash.each{ |key, value|
128
- key = key.to_s.downcase
129
- raise ArgumentError unless valid.include?(key)
130
- send("#{key}=", value)
131
- }
132
-
133
- if to.nil? || subject.nil? || body.nil?
134
- raise ArgumentError, "Missing :to, :subject or :body"
135
- end
136
-
137
- if from.nil?
138
- from = Etc.getlogin + '@' + Socket.gethostname
139
- end
36
+ # A single email address or an array of email addresses to whom
37
+ # the email should be sent. Mandatory.
38
+ attr_accessor :to
39
+
40
+ # A single email address from whom the email is being delivered. The
41
+ # default is your login + '@' + your host name, though it is recommended
42
+ # that you specify it explicitly.
43
+ attr_accessor :from
44
+
45
+ # The subject of the email. Mandatory.
46
+ attr_accessor :subject
47
+
48
+ # The body of the email. Mandatory.
49
+ attr_accessor :body
50
+
51
+ # Creates a new EZ::Email object. As a general rule you won't use
52
+ # this method, but should use EZ::Email.deliver instead.
53
+ #
54
+ def initialize(options={})
55
+ raise TypeError unless options.is_a?(Hash)
56
+ options[:from] ||= Etc.getlogin + '@' + Socket.gethostname
57
+ validate_options(options)
58
+ @options = options
59
+ end
60
+
61
+ # Sends the email based on the options passed to the constructor.
62
+ # As a general rule you won't use this method directly, but should
63
+ # use EZ::Email.deliver instead.
64
+ #
65
+ def deliver
66
+ host = EZ::Email.mail_host
67
+ port = EZ::Email.mail_port
68
+
69
+ to_list = self.to.is_a?(Array) ? self.to : [self.to]
70
+
71
+ Net::SMTP.start(host, port, host){ |smtp|
72
+ smtp.open_message_stream(self.from, self.to){ |stream|
73
+ stream.puts "From: #{self.from}"
74
+ stream.puts "To: " + to_list.join(', ')
75
+ stream.puts "Subject: #{self.subject}"
76
+ stream.puts
77
+ stream.puts self.body
78
+ }
79
+ }
80
+ end
81
+
82
+ # Delivers a simple text email message using four options:
83
+ #
84
+ # * to
85
+ # * from
86
+ # * subject
87
+ # * body
88
+ #
89
+ # Examples:
90
+ #
91
+ # # Send an email to a single user
92
+ # EZ::Email.deliver(
93
+ # :to => 'some_user@hotmail.com',
94
+ # :from => 'me@hotmail.com',
95
+ # :subject => 'Hi',
96
+ # :body => 'How are you?'
97
+ # )
98
+ #
99
+ # # Send an email to a multiple users
100
+ # EZ::Email.deliver(
101
+ # :to => ['jon@hotmail.com', 'mary@hotmail.com'],
102
+ # :from => 'me@hotmail.com',
103
+ # :subject => 'Hi',
104
+ # :body => 'How are you?'
105
+ # )
106
+ #
107
+ # This is a shortcut for EZ::Email.new + EZ::Email#deliver.
108
+ #
109
+ def self.deliver(options)
110
+ new(options).deliver
111
+ end
112
+
113
+ private
114
+
115
+ # Private method that both validates the hash options, and sets
116
+ # the attribute values.
117
+ #
118
+ def validate_options(hash)
119
+ valid = %w[to from subject body]
120
+
121
+ hash.each{ |key, value|
122
+ key = key.to_s.downcase
123
+ raise ArgumentError unless valid.include?(key)
124
+ send("#{key}=", value)
125
+ }
126
+
127
+ if to.nil? || subject.nil? || body.nil?
128
+ raise ArgumentError, "Missing :to, :subject or :body"
140
129
  end
141
- end
130
+ end
131
+ end
142
132
  end
@@ -3,74 +3,145 @@
3
3
  #
4
4
  # Test suite for the EZ::Email library.
5
5
  ########################################################################
6
- require 'test/unit'
6
+ require 'test-unit'
7
7
  require 'ez/email'
8
+ require 'socket'
9
+ require 'etc'
8
10
 
9
11
  class TC_EZ_Email < Test::Unit::TestCase
10
- def setup
11
- @to = 'foo@some_mail_service.com'
12
- @from = 'bar@some_mail_service.com'
13
- @subj = 'This is a test'
14
- @body = 'How are you?'
15
-
16
- @opts = {:to => @to, :from => @from, :subject => @subj, :body => @body }
17
- @email = EZ::Email.new(@opts)
18
- end
19
-
20
- def test_version
21
- assert_equal('0.1.2', EZ::Email::VERSION)
22
- end
23
-
24
- def test_to
25
- assert_respond_to(@email, :to)
26
- assert_respond_to(@email, :to=)
27
- assert_equal(@to, @email.to)
28
- end
29
-
30
- def test_from
31
- assert_respond_to(@email, :from)
32
- assert_respond_to(@email, :from=)
33
- assert_equal(@from, @email.from)
34
- end
35
-
36
- def test_subject
37
- assert_respond_to(@email, :subject)
38
- assert_respond_to(@email, :subject=)
39
- assert_equal(@subj, @email.subject)
40
- end
41
-
42
- def test_body
43
- assert_respond_to(@email, :body)
44
- assert_respond_to(@email, :body=)
45
- assert_equal(@body, @email.body)
46
- end
47
-
48
- def test_mail_host
49
- assert_respond_to(EZ::Email, :mail_host)
50
- assert_respond_to(EZ::Email, :mail_host=)
51
- assert_kind_of(String, EZ::Email.mail_host)
52
- end
53
-
54
- def test_mail_port
55
- assert_respond_to(EZ::Email, :mail_port)
56
- assert_respond_to(EZ::Email, :mail_port=)
57
- assert_equal(25, EZ::Email.mail_port)
58
- end
59
-
60
- def test_deliver
61
- assert_respond_to(EZ::Email, :deliver)
62
- end
63
-
64
- def test_invalid_option_raises_error
65
- assert_raise(ArgumentError){ EZ::Email.send(:new, {:bogus => 77}) }
66
- end
67
-
68
- def teardown
69
- @to = nil
70
- @from = nil
71
- @subj = nil
72
- @body = nil
73
- @opts = nil
74
- @email = nil
75
- end
12
+ def self.startup
13
+ @@host = Socket.gethostname
14
+ @@login = Etc.getlogin
15
+ end
16
+
17
+ def setup
18
+ @to = 'foo@some_mail_service.com'
19
+ @from = 'bar@some_mail_service.com'
20
+ @subj = 'This is a test'
21
+ @body = 'How are you?'
22
+
23
+ @opts = {:to => @to, :from => @from, :subject => @subj, :body => @body }
24
+ @email = EZ::Email.new(@opts)
25
+ end
26
+
27
+ test "version is set to expected value" do
28
+ assert_equal('0.2.1', EZ::Email::VERSION)
29
+ assert_true(EZ::Email::VERSION.frozen?)
30
+ end
31
+
32
+ test "to getter method basic functionality" do
33
+ assert_respond_to(@email, :to)
34
+ assert_nothing_raised{ @email.to }
35
+ assert_not_nil(@email.to)
36
+ end
37
+
38
+ test "to getter method returns expected value" do
39
+ assert_equal(@to, @email.to)
40
+ end
41
+
42
+ test "to setter method basic functionality" do
43
+ assert_respond_to(@email, :to=)
44
+ assert_nothing_raised{ @email.to = 'bogus@some_bogus.com' }
45
+ end
46
+
47
+ test "to setter actually sets value" do
48
+ @email.to = 'bogus@some_bogus.com'
49
+ assert_equal(@email.to, 'bogus@some_bogus.com')
50
+ end
51
+
52
+ test "from getter basic functionality" do
53
+ assert_respond_to(@email, :from)
54
+ assert_nothing_raised{ @email.from }
55
+ assert_not_nil(@email.from)
56
+ end
57
+
58
+ test "from setter basic functionality" do
59
+ assert_respond_to(@email, :from=)
60
+ assert_nothing_raised{ @email.from = 'bogus@some_bogus.com' }
61
+ end
62
+
63
+ test "from method returns expected value" do
64
+ assert_equal(@from, @email.from)
65
+ end
66
+
67
+ test "from defaults to username@host if not set in constructor" do
68
+ @email = EZ::Email.new(:to => 'x', :subject => 'x', :body => 'x')
69
+ expected = @@login << '@' << @@host
70
+ assert_equal(expected, @email.from)
71
+ end
72
+
73
+ test "subject getter basic functionality" do
74
+ assert_respond_to(@email, :subject)
75
+ assert_nothing_raised{ @email.subject }
76
+ assert_not_nil(@email.subject)
77
+ end
78
+
79
+ test "subject setter basic functionality" do
80
+ assert_respond_to(@email, :subject=)
81
+ assert_nothing_raised{ @email.subject = 'bogus@bogus.com' }
82
+ end
83
+
84
+ test "subject method returns expected value" do
85
+ assert_equal(@subj, @email.subject)
86
+ end
87
+
88
+ test "body getter basic functionality" do
89
+ assert_respond_to(@email, :body)
90
+ assert_nothing_raised{ @email.body }
91
+ assert_not_nil(@email.body)
92
+ end
93
+
94
+ test "body setter basic functionality" do
95
+ assert_respond_to(@email, :body=)
96
+ assert_nothing_raised{ @email.body = "Test" }
97
+ end
98
+
99
+ test "body method returns the expected value" do
100
+ assert_equal(@body, @email.body)
101
+ end
102
+
103
+ test "mail_host getter basic functionality" do
104
+ assert_respond_to(EZ::Email, :mail_host)
105
+ assert_nothing_raised{ EZ::Email.mail_host }
106
+ assert_not_nil(EZ::Email.mail_host)
107
+ end
108
+
109
+ test "mail_host setter basic functionality" do
110
+ assert_respond_to(EZ::Email, :mail_host=)
111
+ assert_nothing_raised{ EZ::Email.mail_host = "Test" }
112
+ end
113
+
114
+ test "mail_port singleton getter basic functionality" do
115
+ assert_respond_to(EZ::Email, :mail_port)
116
+ end
117
+
118
+ test "mail_port singleton setter basic functionality" do
119
+ assert_respond_to(EZ::Email, :mail_port=)
120
+ end
121
+
122
+ test "mail_port method returns the expected value" do
123
+ assert_equal(25, EZ::Email.mail_port)
124
+ end
125
+
126
+ test "deliver singleton method basic functionality" do
127
+ assert_respond_to(EZ::Email, :deliver)
128
+ end
129
+
130
+ test "passing an invalid option to the constructor raises an error" do
131
+ assert_raise(ArgumentError){ EZ::Email.send(:new, {:bogus => 77}) }
132
+ end
133
+
134
+ def teardown
135
+ @to = nil
136
+ @from = nil
137
+ @subj = nil
138
+ @body = nil
139
+ @opts = nil
140
+ @email = nil
141
+ end
142
+
143
+ def self.shutdown
144
+ @@host = nil
145
+ @@login = nil
146
+ end
76
147
  end
metadata CHANGED
@@ -1,73 +1,107 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ez-email
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Daniel Berger
14
8
  autorequire:
15
9
  bindir: bin
16
- cert_chain: []
17
-
18
- date: 2011-09-01 00:00:00 Z
19
- dependencies: []
20
-
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
14
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
16
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
18
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
19
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
20
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
21
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
22
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
23
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
24
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
25
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
26
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
27
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
28
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
29
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
30
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
31
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
32
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
33
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
34
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
35
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
+ -----END CERTIFICATE-----
38
+ date:
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: test-unit
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
21
54
  description: A very simple interface for sending email
22
55
  email: djberg96@gmail.com
23
56
  executables: []
24
-
25
57
  extensions: []
26
-
27
- extra_rdoc_files:
58
+ extra_rdoc_files:
28
59
  - README
29
60
  - CHANGES
30
61
  - MANIFEST
31
- files:
62
+ files:
63
+ - LICENSE
64
+ - test
65
+ - test/test_ez_email.rb
32
66
  - CHANGES
33
- - ez-email.gemspec
34
- - lib/ez/email.rb
35
67
  - MANIFEST
36
- - Rakefile
68
+ - ez-email.gemspec
37
69
  - README
38
- - test/test_ez_email.rb
39
- homepage: http://www.rubyforge.org/projects/shards
40
- licenses:
41
- - Artistic 2.0
70
+ - Rakefile
71
+ - certs
72
+ - certs/djberg96_pub.pem
73
+ - lib
74
+ - lib/ez-email.rb
75
+ - lib/ez
76
+ - lib/ez/email.rb
77
+ homepage: https://github.com/djberg96/ez-email
78
+ licenses:
79
+ - Apache-2.0
80
+ metadata:
81
+ homepage_uri: https://github.com/djberg96/ez-email
82
+ bug_tracker_uri: https://github.com/djberg96/ez-email/issues
83
+ changelog_uri: https://github.com/djberg96/ez-email/blob/master/CHANGES
84
+ documentation_uri: https://github.com/djberg96/ez-email/wiki
85
+ source_code_uri: https://github.com/djberg96/ez-email
86
+ wiki_uri: https://github.com/djberg96/ez-email/wiki
42
87
  post_install_message:
43
88
  rdoc_options: []
44
-
45
- require_paths:
89
+ require_paths:
46
90
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
- requirements:
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
50
93
  - - ">="
51
- - !ruby/object:Gem::Version
52
- hash: 3
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
59
98
  - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
- version: "0"
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
65
101
  requirements: []
66
-
67
- rubyforge_project: shards
68
- rubygems_version: 1.8.10
102
+ rubygems_version: 3.0.8
69
103
  signing_key:
70
- specification_version: 3
104
+ specification_version: 4
71
105
  summary: Really easy emails
72
- test_files:
106
+ test_files:
73
107
  - test/test_ez_email.rb
Binary file