trikle-mail 0.0.1 → 0.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.
- checksums.yaml +4 -4
- data/bin/trikle-mail +54 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ae726b20a132beb497b8bdbee1078af61dc4a0a
|
4
|
+
data.tar.gz: 4cf793465fcdd362ffa97162b721a80494b948ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 244dc76d34e37e445262421580dc2eb30c6cfe95243df9418bcb049722a5ea07c107112f029cdf575d73f47cc6545213c94791d63bd3d1b7dd7c8b5ecf9f46c0
|
7
|
+
data.tar.gz: dea0cd0f556f008ae175d68a3645fa88512cc5edd138df2ab84518f5f1320635d8f56eb4a9cc04869adfeb8a67a2027efeced4eccf4274e04a9009b1d31ecf6d
|
data/bin/trikle-mail
CHANGED
@@ -2,16 +2,69 @@
|
|
2
2
|
require 'commander'
|
3
3
|
require 'mandrill'
|
4
4
|
require 'csv'
|
5
|
+
require 'mail'
|
5
6
|
|
6
7
|
class TrikleMail
|
7
8
|
extend Commander::Methods
|
8
|
-
|
9
|
+
|
9
10
|
program :name, 'Trikle Mail'
|
10
11
|
program :version, '0.0.0'
|
11
12
|
program :description, 'Send your bulk email in a trikle over the mandril api'
|
12
13
|
|
13
14
|
default_command :run
|
14
15
|
|
16
|
+
command :smtp do |c|
|
17
|
+
c.syntax = 'trikle-mail smtp csv_of_emails.csv [options]'
|
18
|
+
c.description = 'Send a message to each email in the csv using the template'
|
19
|
+
c.option '--host STRING', String, 'The host of the mail server e.g. <mail.gmail.com>'
|
20
|
+
c.option '--port INTEGER', Integer, 'Port number of the mail server e.g. 587'
|
21
|
+
c.option '--username STRING', String, 'Username to authenticate with mail server'
|
22
|
+
c.option '--password STRING', String, 'Password to authenticate with mail server'
|
23
|
+
c.option '--from STRING', String, 'The email address to send the email from'
|
24
|
+
c.option '--template STRING', String, 'The template to use to send the message'
|
25
|
+
c.option '--subject STRING', String, 'The subject line of the message'
|
26
|
+
c.option '--hours INTEGER', Integer, 'The number of hours over which to send the emails'
|
27
|
+
c.option '--minutes INTEGER', Integer, 'The number of minutes over which to send the emails'
|
28
|
+
|
29
|
+
c.action do |args, options|
|
30
|
+
title_row, *data_rows = CSV.read(args[0])
|
31
|
+
|
32
|
+
data_hashes = data_rows.map do |row|
|
33
|
+
title_row.map.with_index do |title, index|
|
34
|
+
[title.downcase.to_sym, row[index]]
|
35
|
+
end.to_h
|
36
|
+
end
|
37
|
+
|
38
|
+
options.default({hours: 0, minutes: 0})
|
39
|
+
time_range = ((options.hours * 60 * 60) + (options.minutes * 60)) /
|
40
|
+
data_hashes.length.to_f
|
41
|
+
|
42
|
+
data_hashes.each do |hash|
|
43
|
+
|
44
|
+
mail = Mail.new do
|
45
|
+
from hash.fetch(:from, options.from)
|
46
|
+
to hash.fetch(:to, hash.fetch(:email) { raise 'no email address found in to column!' })
|
47
|
+
subject hash.fetch(:subject, options.subject)
|
48
|
+
body File.read(hash.fetch(:template, options.template)) % hash
|
49
|
+
end
|
50
|
+
|
51
|
+
mail.delivery_method :smtp, {
|
52
|
+
address: hash.fetch(:host, options.host),
|
53
|
+
port: hash.fetch(:port, options.port),
|
54
|
+
user_name: hash.fetch(:username, options.username),
|
55
|
+
password: hash.fetch(:password, options.password),
|
56
|
+
authentication: :login,
|
57
|
+
enable_starttls_auto: true
|
58
|
+
}
|
59
|
+
|
60
|
+
puts mail.deliver!
|
61
|
+
random_wait_time = rand(0..time_range)
|
62
|
+
puts "waiting #{random_wait_time} seconds"
|
63
|
+
sleep(random_wait_time)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
15
68
|
command :run do |c|
|
16
69
|
c.syntax = 'trikle-mail csv_of_emails.csv [options]'
|
17
70
|
c.description = 'Send a message to each email address in the csv'
|