trikle-mail 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/trikle-mail +22 -5
  3. data/lib/triklemailer.rb +22 -8
  4. metadata +34 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bc1f6ac3d5593c2b07c79554fd73ac007913e2b8e257d044611328eca81d1c5
4
- data.tar.gz: 779eb9f435e07e043f91d5eff45d2092a16076049157dbbbfaa1ee785b99cf5b
3
+ metadata.gz: 5fab487bbbcc70e117b9884b48d1b006b605b4c1403562563b3c6dc3cae68d96
4
+ data.tar.gz: f3540074f297409efce8c7e80a61a485d11f187683f51f3df5e8739b32760e1e
5
5
  SHA512:
6
- metadata.gz: 7b9635c1c57938ea53c143458d48587234855f6b3910b1877c3f99b9bbedef48403748289338c38c2344b27e1915eec6806a8a3dd269225be85661d62fcc8eaa
7
- data.tar.gz: baee1a420a5bcc5cd1ca280b3caee0aae9a0af0f98ff7d8423f49a7f90ab3e0c32cb639773decd0c3021a28edbf66ebbb21ef5d2c196741608099be655c2568e
6
+ metadata.gz: 8e11e92874661ec21e1da315cf4558972a541a7a6ea2143041d941879ce4e867760bfc16b18ebcfd2aa6d18a99522e6e48c8dca6cff12175f0ba1deef2e3314c
7
+ data.tar.gz: 24eec0f470a08d21c079f01c0ea1df8032be712d4c380c0e49f04eac7e97775ab5222a109f5756dd1dc6b8990bce8209535be83afd176f3fda288c890249070d
data/bin/trikle-mail CHANGED
@@ -19,26 +19,43 @@ class TrikleMail
19
19
  c.description = 'Send a message to each email in the csv using the template'
20
20
  c.option '--host STRING', String, 'The host of the mail server e.g. <mail.gmail.com>'
21
21
  c.option '--port INTEGER', Integer, 'Port number of the mail server e.g. 587'
22
+ c.option '--domain STRING', String, 'Domain that emails are comming from'
22
23
  c.option '--username STRING', String, 'Username to authenticate with mail server'
23
24
  c.option '--password STRING', String, 'Password to authenticate with mail server'
24
25
  c.option '--from STRING', String, 'The email address to send the email from'
26
+ c.option '--bcc STRING', String, 'The email address to bcc each message to'
27
+ c.option '--subject STRING', String, 'The subject line of the message'
25
28
  c.option '--template STRING', String, 'The template to use to send the message'
29
+ c.option '--attachment STTRING', String, 'The relative file path to your attachement'
26
30
  c.option '--html', 'toggle using html to format email, defaults to no'
27
- c.option '--subject STRING', String, 'The subject line of the message'
28
31
  c.option '--hours INTEGER', Integer, 'The number of hours over which to send the emails'
29
32
  c.option '--minutes INTEGER', Integer, 'The number of minutes over which to send the emails'
33
+ c.option '--oauth2-token', String, 'Authenticates your request with an Oauth 2.0 token instead of a password'
30
34
 
31
35
  c.action do |args, options|
32
- recipients = CSV.new(args[0], headers: true).map(&:to_h)
33
- sent_file_name = ['sent', options.template.split('.').first].join('_')
34
- sent = CSV.new(sent_file_name, headers: true).map { |r| r[:email] }
36
+ recipients = CSV.new(File.new(args[0]), headers: true, header_converters: :symbol).map(&:to_h)
37
+ sent_file_name = "./#{['sent', options.template.split('.').first].join('_')}.csv"
38
+ sent =
39
+ if File.exists?(sent_file_name)
40
+ CSV.new(File.new(sent_file_name), headers: true, header_converters: :symbol).map { |r| r[:email] }
41
+ else
42
+ []
43
+ end
35
44
 
36
45
  mail_options = Triklemailer::Options.new(
37
46
  template: File.read(options.template),
38
47
  template_name: options.template,
39
48
  is_html: options.template.end_with?('html'),
40
49
  from: options.from,
41
- subject: options.subject
50
+ bcc: options.bcc,
51
+ subject: options.subject,
52
+ port: options.port,
53
+ host: options.host,
54
+ username: options.username,
55
+ password: options.password,
56
+ oauth2_token: options.oauth2_token,
57
+ domain: options.domain,
58
+ attachment: options.attachment
42
59
  )
43
60
 
44
61
  Triklemailer.send_mail(mail_options, recipients, sent)
data/lib/triklemailer.rb CHANGED
@@ -2,8 +2,13 @@ require 'mail'
2
2
  require 'csv'
3
3
 
4
4
  module Triklemailer
5
- VERSION = '0.0.6'
6
- Options = Struct.new(:template, :template_name, :is_html, :from, :subject, keyword_init: true)
5
+ VERSION = '0.1.0'
6
+ Options = Struct.new(
7
+ :template, :template_name, :is_html, :from, :subject,
8
+ :host, :port, :username, :password, :bcc, :domain,
9
+ :attachment, :oauth2_token,
10
+ keyword_init: true
11
+ )
7
12
 
8
13
  # It should take:
9
14
  # * A list of emails and data
@@ -43,6 +48,7 @@ module Triklemailer
43
48
  to recipient.fetch(:to, recipient.fetch(:email) {
44
49
  raise "Some rows are missing either a 'to' or 'email' column."
45
50
  })
51
+ bcc options.bcc if options.bcc
46
52
  subject recipient.fetch(:subject, options.subject)
47
53
 
48
54
  if options.is_html
@@ -55,17 +61,22 @@ module Triklemailer
55
61
  body cleaned_template % recipient
56
62
  end
57
63
  end
64
+
65
+ add_file(File.expand_path(options.attachment)) if options.attachment
58
66
  end
59
67
 
60
68
  if block_given?
61
69
  yield(mail, recipient)
62
70
  else
71
+ oauth2_token = recipient.fetch(:oauth2_token, options.oauth2_token)
72
+ password = recrecipient.fetch(:password, options.password)
73
+
63
74
  mail.delivery_method :smtp, {
64
75
  address: recipient.fetch(:host, options.host),
65
76
  port: recipient.fetch(:port, options.port),
66
77
  user_name: recipient.fetch(:username, options.username),
67
- password: recipient.fetch(:password, options.password),
68
- authentication: :login,
78
+ password: oauth2_token || password,
79
+ authentication: oauth2_token ? :xoauth2 : :login,
69
80
  enable_starttls_auto: true
70
81
  }
71
82
  end
@@ -78,18 +89,21 @@ module Triklemailer
78
89
  options.template_name)
79
90
  rescue => e
80
91
  puts "Failed to send email to #{recipient[:email]}."
92
+ puts e.class
93
+ puts e
94
+ puts e.backtrace
81
95
  next
82
96
  end
83
97
  end
84
98
  end
85
99
 
86
- def log_sent(email, template)
87
- log_file_name = ['sent', template.split('.').first].join('_')
100
+ def self.log_sent(email, template)
101
+ log_file_name = "./#{['sent', template.split('.').first].join('_')}.csv"
88
102
 
89
103
  CSV.open(
90
- "./#{log_file_name}.csv",
104
+ log_file_name,
91
105
  'a',
92
- write_headers: true,
106
+ write_headers: !File.exists?(log_file_name),
93
107
  headers: ['email', 'sent_at']
94
108
  ) do |csv|
95
109
  csv << [email, Time.now]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trikle-mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasper Lyons
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mail_xoauth2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Send bulk email in a trickle over mandrill
84
112
  email: jasper.lyons@gmail.com
85
113
  executables:
@@ -93,7 +121,7 @@ homepage: ''
93
121
  licenses:
94
122
  - MIT
95
123
  metadata: {}
96
- post_install_message:
124
+ post_install_message:
97
125
  rdoc_options: []
98
126
  require_paths:
99
127
  - lib
@@ -108,8 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
136
  - !ruby/object:Gem::Version
109
137
  version: '0'
110
138
  requirements: []
111
- rubygems_version: 3.0.3
112
- signing_key:
139
+ rubygems_version: 3.2.32
140
+ signing_key:
113
141
  specification_version: 4
114
142
  summary: Send a trickle of mail
115
143
  test_files: []