bulkmail 0.1 → 0.2
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.
- data/CHANGELOG +12 -0
- data/README +11 -12
- data/Rakefile +1 -2
- data/bin/bulkmail +42 -31
- data/doc/rdoc/classes/Array.html +155 -0
- data/doc/rdoc/classes/BulkMail.html +310 -0
- data/doc/rdoc/classes/String.html +178 -0
- data/doc/rdoc/classes/Symbol.html +155 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGELOG.html +165 -0
- data/doc/rdoc/files/COPYING.html +129 -0
- data/doc/rdoc/files/README.html +160 -0
- data/doc/rdoc/files/lib/bulkmail_rb.html +108 -0
- data/doc/rdoc/fr_class_index.html +30 -0
- data/doc/rdoc/fr_file_index.html +30 -0
- data/doc/rdoc/fr_method_index.html +35 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/lib/bulkmail.rb +97 -62
- metadata +22 -12
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -21,22 +21,21 @@ where the options are:
|
|
21
21
|
|
22
22
|
You can also include headers in the content file, provided they are followed by a blank line. For example:
|
23
23
|
|
24
|
-
Subject:
|
24
|
+
Subject: My New Thing
|
25
|
+
Content-Type: text/html; charset=UTF-8
|
25
26
|
|
26
|
-
|
27
|
-
A special concert is about to take place this Thursday at...
|
27
|
+
<html><body><h1>My New Thing!</h1></body></html>
|
28
28
|
|
29
29
|
=== From Ruby
|
30
30
|
|
31
|
-
BulkMail.
|
31
|
+
BulkMail.send_bulk(sender, recipients, content, headers)
|
32
32
|
|
33
|
-
|
34
|
-
[
|
35
|
-
[
|
36
|
-
[
|
37
|
-
[
|
38
|
-
[:additional_headers] additional headers
|
33
|
+
Where:
|
34
|
+
[sender] is the sender address. This address will also be used as in the form and to headers.
|
35
|
+
[recipients] is an array of email addresses
|
36
|
+
[content] is the message content
|
37
|
+
[headers] is an array containing message headers.
|
39
38
|
|
40
|
-
You can
|
39
|
+
You can change server settings by using BulkMail.server_settings:
|
41
40
|
|
42
|
-
BulkMail.server_settings[:
|
41
|
+
BulkMail.server_settings[:host] = 'mail.example.com'
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'fileutils'
|
|
7
7
|
include FileUtils
|
8
8
|
|
9
9
|
NAME = "bulkmail"
|
10
|
-
VERS = "0.
|
10
|
+
VERS = "0.2"
|
11
11
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
12
12
|
RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation",
|
13
13
|
"--opname", "index.html",
|
@@ -44,7 +44,6 @@ spec = Gem::Specification.new do |s|
|
|
44
44
|
s.homepage = 'http://code.google.com/p/bulkmail/'
|
45
45
|
s.executables = ['bulkmail']
|
46
46
|
|
47
|
-
s.add_dependency('actionmailer')
|
48
47
|
s.required_ruby_version = '>= 1.8.2'
|
49
48
|
|
50
49
|
s.files = %w(COPYING README Rakefile) + Dir.glob("{bin,doc,lib}/**/*")
|
data/bin/bulkmail
CHANGED
@@ -2,9 +2,27 @@
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'optparse'
|
5
|
+
require 'bulkmail'
|
6
|
+
|
7
|
+
$sender = nil
|
8
|
+
$recipients = []
|
9
|
+
$content = nil
|
10
|
+
$headers = {}
|
5
11
|
|
6
|
-
|
7
|
-
|
12
|
+
def parse_file(fn)
|
13
|
+
lines = IO.readlines(fn)
|
14
|
+
while line = lines.shift
|
15
|
+
break if line.empty?
|
16
|
+
if line =~ /^(.+):\s?(.*)$/
|
17
|
+
$headers ||= {}
|
18
|
+
$headers[$1] = $2
|
19
|
+
else
|
20
|
+
lines.unshift(line)
|
21
|
+
break
|
22
|
+
end
|
23
|
+
end
|
24
|
+
$content = lines.join
|
25
|
+
end
|
8
26
|
|
9
27
|
opts = OptionParser.new do |opts|
|
10
28
|
opts.banner = "Usage: bulkmail <options>"
|
@@ -13,39 +31,39 @@ opts = OptionParser.new do |opts|
|
|
13
31
|
opts.separator "Options:"
|
14
32
|
|
15
33
|
opts.on("-h", "--host HOSTNAME", "SMPT host name. Default is localhost.") do |v|
|
16
|
-
|
34
|
+
BulkMail.server_settings[:host] = v
|
17
35
|
end
|
18
36
|
|
19
|
-
opts.on("-
|
20
|
-
|
37
|
+
opts.on("-u", "--user username", "User name (for authentication)") do |v|
|
38
|
+
BulkMail.server_settings[:user] = v
|
21
39
|
end
|
22
40
|
|
23
|
-
opts.on("-
|
24
|
-
|
41
|
+
opts.on("-p", "--password password", "Password (for authentication)") do |v|
|
42
|
+
BulkMail.server_settings[:password] = v
|
25
43
|
end
|
26
44
|
|
27
|
-
opts.on("-
|
28
|
-
|
45
|
+
opts.on("-a", "--authentication type", "Authentication type") do |v|
|
46
|
+
BulkMail.server_settings[:auth] = v
|
29
47
|
end
|
30
48
|
|
31
|
-
opts.on("-
|
32
|
-
|
49
|
+
opts.on("-r", "--recipients filename", "Recipients file name") do |v|
|
50
|
+
$recipients = IO.readlines(v).map {|l| l =~ /(.*)(\r\n|\n)$/; $1}
|
33
51
|
end
|
34
52
|
|
35
|
-
opts.on("-
|
36
|
-
|
53
|
+
opts.on("-c", "--content filename", "Content file name") do |v|
|
54
|
+
parse_file(v)
|
37
55
|
end
|
38
56
|
|
39
|
-
opts.on("-
|
40
|
-
|
57
|
+
opts.on("-s", "--subject subject", "Subject line") do |v|
|
58
|
+
$headers[:subject] = v
|
41
59
|
end
|
42
60
|
|
43
|
-
opts.on("-
|
44
|
-
|
61
|
+
opts.on("-f", "--from from", "From address") do |v|
|
62
|
+
$sender = v
|
45
63
|
end
|
46
64
|
|
47
65
|
opts.on("-m", "--mime type", "MIME type") do |v|
|
48
|
-
|
66
|
+
$headers[:content_type] = v
|
49
67
|
end
|
50
68
|
|
51
69
|
# No argument, shows at tail. This will print an options summary.
|
@@ -68,24 +86,17 @@ begin
|
|
68
86
|
opts.parse! ARGV
|
69
87
|
rescue => e
|
70
88
|
puts e.message
|
89
|
+
puts e.backtrace.first
|
71
90
|
exit
|
72
91
|
end
|
73
92
|
|
74
|
-
unless
|
93
|
+
unless $content
|
75
94
|
puts opts
|
76
95
|
exit
|
77
96
|
end
|
78
97
|
|
79
|
-
|
80
|
-
|
81
|
-
BulkMail.server_settings[:address] = config[:host] if config[:host]
|
82
|
-
BulkMail.server_settings[:user_name] = config[:user] if config[:user]
|
83
|
-
BulkMail.server_settings[:password] = config[:password] if config[:password]
|
84
|
-
BulkMail.server_settings[:authentication] = config[:authentication].to_sym if config[:authentication]
|
85
|
-
|
86
|
-
p BulkMail.server_settings
|
98
|
+
trap('INT') {exit}
|
87
99
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
puts "Message sent to #{job.delivered} of #{job.total} recipients."
|
100
|
+
puts "Please hold on..."
|
101
|
+
$sender ||= $headers['From']
|
102
|
+
BulkMail.send_bulk($sender, $recipients, $content, $headers)
|
@@ -0,0 +1,155 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Array</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Array</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/bulkmail_rb.html">
|
59
|
+
lib/bulkmail.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000007">split</a>
|
90
|
+
</div>
|
91
|
+
</div>
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
|
96
|
+
<!-- if includes -->
|
97
|
+
|
98
|
+
<div id="section">
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
<!-- if method_list -->
|
108
|
+
<div id="methods">
|
109
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
110
|
+
|
111
|
+
<div id="method-M000007" class="method-detail">
|
112
|
+
<a name="M000007"></a>
|
113
|
+
|
114
|
+
<div class="method-heading">
|
115
|
+
<a href="#M000007" class="method-signature">
|
116
|
+
<span class="method-name">split</span><span class="method-args">(batch)</span>
|
117
|
+
</a>
|
118
|
+
</div>
|
119
|
+
|
120
|
+
<div class="method-description">
|
121
|
+
<p>
|
122
|
+
Splits the array into smaller arrays of fixed size
|
123
|
+
</p>
|
124
|
+
<p><a class="source-toggle" href="#"
|
125
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
126
|
+
<div class="method-source-code" id="M000007-source">
|
127
|
+
<pre>
|
128
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 27</span>
|
129
|
+
27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">split</span>(<span class="ruby-identifier">batch</span>)
|
130
|
+
28: <span class="ruby-identifier">result</span> = []
|
131
|
+
29: <span class="ruby-identifier">idx</span> = <span class="ruby-value">0</span>
|
132
|
+
30: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">idx</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">size</span>
|
133
|
+
31: <span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">slice</span>(<span class="ruby-identifier">idx</span>, <span class="ruby-identifier">batch</span>)
|
134
|
+
32: <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">batch</span>
|
135
|
+
33: <span class="ruby-keyword kw">end</span>
|
136
|
+
34: <span class="ruby-identifier">result</span>
|
137
|
+
35: <span class="ruby-keyword kw">end</span>
|
138
|
+
</pre>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
</div>
|
142
|
+
|
143
|
+
|
144
|
+
</div>
|
145
|
+
|
146
|
+
|
147
|
+
</div>
|
148
|
+
|
149
|
+
|
150
|
+
<div id="validator-badges">
|
151
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
152
|
+
</div>
|
153
|
+
|
154
|
+
</body>
|
155
|
+
</html>
|
@@ -0,0 +1,310 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: BulkMail</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">BulkMail</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/bulkmail_rb.html">
|
59
|
+
lib/bulkmail.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
</div>
|
84
|
+
|
85
|
+
<div id="method-list">
|
86
|
+
<h3 class="section-bar">Methods</h3>
|
87
|
+
|
88
|
+
<div class="name-list">
|
89
|
+
<a href="#M000002">format_headers</a>
|
90
|
+
<a href="#M000005">send_bulk</a>
|
91
|
+
<a href="#M000004">send_message</a>
|
92
|
+
<a href="#M000001">server_settings</a>
|
93
|
+
<a href="#M000003">smtp</a>
|
94
|
+
</div>
|
95
|
+
</div>
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
|
100
|
+
<!-- if includes -->
|
101
|
+
|
102
|
+
<div id="section">
|
103
|
+
|
104
|
+
|
105
|
+
<div id="constants-list">
|
106
|
+
<h3 class="section-bar">Constants</h3>
|
107
|
+
|
108
|
+
<div class="name-list">
|
109
|
+
<table summary="Constants">
|
110
|
+
<tr class="top-aligned-row context-row">
|
111
|
+
<td class="context-item-name">LINE_BREAK</td>
|
112
|
+
<td>=</td>
|
113
|
+
<td class="context-item-value">"\r\n"</td>
|
114
|
+
</tr>
|
115
|
+
<tr class="top-aligned-row context-row">
|
116
|
+
<td class="context-item-name">HEADER_FMT</td>
|
117
|
+
<td>=</td>
|
118
|
+
<td class="context-item-value">"%s: %s\r\n".freeze</td>
|
119
|
+
</tr>
|
120
|
+
</table>
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
<!-- if method_list -->
|
130
|
+
<div id="methods">
|
131
|
+
<h3 class="section-bar">Public Class methods</h3>
|
132
|
+
|
133
|
+
<div id="method-M000002" class="method-detail">
|
134
|
+
<a name="M000002"></a>
|
135
|
+
|
136
|
+
<div class="method-heading">
|
137
|
+
<a href="#M000002" class="method-signature">
|
138
|
+
<span class="method-name">format_headers</span><span class="method-args">(headers)</span>
|
139
|
+
</a>
|
140
|
+
</div>
|
141
|
+
|
142
|
+
<div class="method-description">
|
143
|
+
<p>
|
144
|
+
Returns the message headers formatted
|
145
|
+
</p>
|
146
|
+
<p><a class="source-toggle" href="#"
|
147
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
148
|
+
<div class="method-source-code" id="M000002-source">
|
149
|
+
<pre>
|
150
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 57</span>
|
151
|
+
57: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">format_headers</span>(<span class="ruby-identifier">headers</span>)
|
152
|
+
58: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value str">''</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>, <span class="ruby-identifier">kv</span><span class="ruby-operator">|</span>
|
153
|
+
59: <span class="ruby-identifier">m</span> <span class="ruby-operator"><<</span> (<span class="ruby-constant">HEADER_FMT</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">kv</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_header</span>, <span class="ruby-identifier">kv</span>[<span class="ruby-value">1</span>]])
|
154
|
+
60: <span class="ruby-keyword kw">end</span>
|
155
|
+
61: <span class="ruby-keyword kw">end</span>
|
156
|
+
</pre>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
|
161
|
+
<div id="method-M000005" class="method-detail">
|
162
|
+
<a name="M000005"></a>
|
163
|
+
|
164
|
+
<div class="method-heading">
|
165
|
+
<a href="#M000005" class="method-signature">
|
166
|
+
<span class="method-name">send_bulk</span><span class="method-args">(sender, recipients, body, headers)</span>
|
167
|
+
</a>
|
168
|
+
</div>
|
169
|
+
|
170
|
+
<div class="method-description">
|
171
|
+
<p>
|
172
|
+
Sends bulk mail to a large number of recipients.
|
173
|
+
</p>
|
174
|
+
<p><a class="source-toggle" href="#"
|
175
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
176
|
+
<div class="method-source-code" id="M000005-source">
|
177
|
+
<pre>
|
178
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 89</span>
|
179
|
+
89: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send_bulk</span>(<span class="ruby-identifier">sender</span>, <span class="ruby-identifier">recipients</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">headers</span>)
|
180
|
+
90: <span class="ruby-identifier">failed</span> = []
|
181
|
+
91: <span class="ruby-identifier">succeeded</span> = []
|
182
|
+
92: <span class="ruby-identifier">headers</span>[<span class="ruby-identifier">:from</span>] = <span class="ruby-identifier">headers</span>[<span class="ruby-identifier">:to</span>] = <span class="ruby-identifier">sender</span>
|
183
|
+
93: <span class="ruby-identifier">recipients</span> = <span class="ruby-identifier">recipients</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">email_addr</span>}.<span class="ruby-identifier">compact</span>
|
184
|
+
94: <span class="ruby-identifier">recipients</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value">10</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">list</span><span class="ruby-operator">|</span>
|
185
|
+
95: <span class="ruby-keyword kw">begin</span>
|
186
|
+
96: <span class="ruby-identifier">smtp</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">send_message</span>(<span class="ruby-identifier">s</span>, <span class="ruby-identifier">sender</span>.<span class="ruby-identifier">email_addr</span>, <span class="ruby-identifier">list</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">headers</span>)}
|
187
|
+
97: <span class="ruby-identifier">succeeded</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">list</span>
|
188
|
+
98: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Sent message to #{list.join(', ')}"</span>
|
189
|
+
99: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
190
|
+
100: <span class="ruby-identifier">failed</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">list</span>
|
191
|
+
101: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Failed to send to #{list.join(', ')}: #{e.message}\r\n#{e.backtrace.first}"</span>
|
192
|
+
102: <span class="ruby-keyword kw">end</span>
|
193
|
+
103: <span class="ruby-keyword kw">end</span>
|
194
|
+
104: <span class="ruby-comment cmt"># log failed addresses</span>
|
195
|
+
105: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">failed</span>.<span class="ruby-identifier">empty?</span>
|
196
|
+
106: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-value str">'failed.bulkmail'</span>, <span class="ruby-value str">'w'</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">failed</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span><span class="ruby-identifier">f</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">l</span>}}
|
197
|
+
107: <span class="ruby-keyword kw">end</span>
|
198
|
+
108: <span class="ruby-identifier">puts</span> <span class="ruby-node">"Message to sent to #{succeeded.size} of #{recipients.size} recipients"</span>
|
199
|
+
109: <span class="ruby-keyword kw">end</span>
|
200
|
+
</pre>
|
201
|
+
</div>
|
202
|
+
</div>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div id="method-M000004" class="method-detail">
|
206
|
+
<a name="M000004"></a>
|
207
|
+
|
208
|
+
<div class="method-heading">
|
209
|
+
<a href="#M000004" class="method-signature">
|
210
|
+
<span class="method-name">send_message</span><span class="method-args">(smtp, from, to, body, headers = nil)</span>
|
211
|
+
</a>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
<div class="method-description">
|
215
|
+
<p>
|
216
|
+
Sends an email
|
217
|
+
</p>
|
218
|
+
<p><a class="source-toggle" href="#"
|
219
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
220
|
+
<div class="method-source-code" id="M000004-source">
|
221
|
+
<pre>
|
222
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 77</span>
|
223
|
+
77: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send_message</span>(<span class="ruby-identifier">smtp</span>, <span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">headers</span> = <span class="ruby-keyword kw">nil</span>)
|
224
|
+
78: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">headers</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">headers</span>.<span class="ruby-identifier">empty?</span>
|
225
|
+
79: <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">format_headers</span>(<span class="ruby-identifier">headers</span>)
|
226
|
+
80: <span class="ruby-keyword kw">else</span>
|
227
|
+
81: <span class="ruby-identifier">msg</span> = <span class="ruby-constant">LINE_BREAK</span>
|
228
|
+
82: <span class="ruby-keyword kw">end</span>
|
229
|
+
83: <span class="ruby-identifier">msg</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">LINE_BREAK</span>
|
230
|
+
84: <span class="ruby-identifier">msg</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">body</span>
|
231
|
+
85: <span class="ruby-identifier">smtp</span>.<span class="ruby-identifier">send_message</span> <span class="ruby-identifier">msg</span>, <span class="ruby-identifier">from</span>, <span class="ruby-identifier">to</span>
|
232
|
+
86: <span class="ruby-keyword kw">end</span>
|
233
|
+
</pre>
|
234
|
+
</div>
|
235
|
+
</div>
|
236
|
+
</div>
|
237
|
+
|
238
|
+
<div id="method-M000001" class="method-detail">
|
239
|
+
<a name="M000001"></a>
|
240
|
+
|
241
|
+
<div class="method-heading">
|
242
|
+
<a href="#M000001" class="method-signature">
|
243
|
+
<span class="method-name">server_settings</span><span class="method-args">()</span>
|
244
|
+
</a>
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div class="method-description">
|
248
|
+
<p>
|
249
|
+
Returns the <a href="BulkMail.html#M000001">server_settings</a> hash
|
250
|
+
</p>
|
251
|
+
<p><a class="source-toggle" href="#"
|
252
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
253
|
+
<div class="method-source-code" id="M000001-source">
|
254
|
+
<pre>
|
255
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 49</span>
|
256
|
+
49: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">server_settings</span>
|
257
|
+
50: <span class="ruby-ivar">@@server_settings</span>
|
258
|
+
51: <span class="ruby-keyword kw">end</span>
|
259
|
+
</pre>
|
260
|
+
</div>
|
261
|
+
</div>
|
262
|
+
</div>
|
263
|
+
|
264
|
+
<div id="method-M000003" class="method-detail">
|
265
|
+
<a name="M000003"></a>
|
266
|
+
|
267
|
+
<div class="method-heading">
|
268
|
+
<a href="#M000003" class="method-signature">
|
269
|
+
<span class="method-name">smtp</span><span class="method-args">() {|smtp| ...}</span>
|
270
|
+
</a>
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div class="method-description">
|
274
|
+
<p>
|
275
|
+
Starts an SMTP session and yields
|
276
|
+
</p>
|
277
|
+
<p><a class="source-toggle" href="#"
|
278
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
279
|
+
<div class="method-source-code" id="M000003-source">
|
280
|
+
<pre>
|
281
|
+
<span class="ruby-comment cmt"># File lib/bulkmail.rb, line 64</span>
|
282
|
+
64: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">smtp</span>
|
283
|
+
65: <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">SMTP</span>.<span class="ruby-identifier">start</span>(
|
284
|
+
66: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:host</span>],
|
285
|
+
67: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:port</span>],
|
286
|
+
68: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:helo_domain</span>] <span class="ruby-operator">||</span> <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:host</span>],
|
287
|
+
69: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:user</span>],
|
288
|
+
70: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:password</span>],
|
289
|
+
71: <span class="ruby-ivar">@@server_settings</span>[<span class="ruby-identifier">:auth</span>]) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">smtp</span><span class="ruby-operator">|</span>
|
290
|
+
72: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">smtp</span>
|
291
|
+
73: <span class="ruby-keyword kw">end</span>
|
292
|
+
74: <span class="ruby-keyword kw">end</span>
|
293
|
+
</pre>
|
294
|
+
</div>
|
295
|
+
</div>
|
296
|
+
</div>
|
297
|
+
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
|
302
|
+
</div>
|
303
|
+
|
304
|
+
|
305
|
+
<div id="validator-badges">
|
306
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
307
|
+
</div>
|
308
|
+
|
309
|
+
</body>
|
310
|
+
</html>
|