mailmerge 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 338924b6f4c4217d0a2dc67e293cc427aa200f0e0938b9f1e6e4c10c224a57f4
4
- data.tar.gz: 26cd2068a730b4f9a4e77137e4ea99a8387b1ade850275d318823142a6468aaf
3
+ metadata.gz: b81dde605d612f8b14856af4d8e640247c49053f770b1ad90e2b66c7e680c57b
4
+ data.tar.gz: 399c2ce3463e2593d37c50b0ceaff767d66392a173b5e14f9cfa7ef86c9694d7
5
5
  SHA512:
6
- metadata.gz: 67003a1bb860ad3e9f144063b1439b5db05967a23eaa0b73127fda09700b8b7ee6d9f5db65c721004e19e9a1678fcd6f2561bbd9d5138d9d4851c37992055766
7
- data.tar.gz: cf3478330a6553159fe37662d2494678e0fff4fcdf30cb531b3c611c3bd33022c20eacc4021637bc5073f4daf181085b60318114ef38bae05a27c1ee6f8b3cfe
6
+ metadata.gz: 49d86c206c1fafe1e7c98f3d54494e0e1d02ec16a4ef0ed91d8400ab22ec034eb84b6495a76d4d24997703428f2522d4af316947e87d774573b3c3e7344a2d3b
7
+ data.tar.gz: 5e2628d21e77457b558629314e4d8d3b5c5efecebc71c5fc5c0c81630e26c864f543f524e6c9b1dc35916a3a27990e721af9cb2c43d29491e6b7d68a9cc323c0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailmerge (0.1.0)
4
+ mailmerge (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Mailmerge
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mailmerge`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Mailmerge is a simple program that takes a list of template arguments in the form of a CSV file and populates an email template (in erb format) with those parameters.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ You can use it to send a simple or formulaic email to multiple people and maintain some amount of personalization per person
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,31 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Example usage:
26
+
27
+ `mailmerge test.csv test.erb x@gmail.com password`
28
+
29
+ Example email template:
30
+
31
+ ```
32
+ FROM: x@gmail.com
33
+ SUBJECT: <%= foo %>
34
+ TO: <%= @to_email %>
35
+
36
+ <%= bar %>
37
+ <%= baz %>
38
+
39
+ Regards,
40
+ Person
41
+ ```
42
+
43
+ Example CSV:
44
+
45
+ ```
46
+ to_email,foo,bar,baz
47
+ y@gmail.com,1,2,3
48
+ z@yahoo.com,4,5,6
49
+ ```
26
50
 
27
51
  ## Development
28
52
 
@@ -32,7 +56,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
56
 
33
57
  ## Contributing
34
58
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mailmerge.
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/MatanSilver/mailmerge.
36
60
 
37
61
  ## License
38
62
 
data/exe/mailmerge CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "mailmerge"
4
+ m = Mailmerge::Merger.new
5
+ m.merge
data/lib/mailmerge.rb CHANGED
@@ -10,17 +10,6 @@ include Open3
10
10
 
11
11
  module Mailmerge
12
12
  class Error < StandardError; end
13
-
14
- smtp = Net::SMTP.new 'smtp.gmail.com', 587
15
- smtp.enable_starttls
16
- arr_of_rows = CSV.read(ARGV[0])
17
- email_template = ARGV[1]
18
- headers = arr_of_rows[0]
19
- rows = arr_of_rows[1..]
20
- template_contents = File.read(ARGV[1])
21
- user_email = ARGV[2]
22
- user_password = ARGV[3]
23
-
24
13
  class TemplateData < ERB
25
14
  def initialize(keys, values, template)
26
15
  @template = template
@@ -34,18 +23,35 @@ module Mailmerge
34
23
  super(binding)
35
24
  end
36
25
  end
26
+ class Merger
27
+ def merge
28
+ if ARGV[0] == "-h"
29
+ puts "usage: mailmerge [csv] [erb] [from_addr] [password]"
30
+ exit
31
+ end
32
+ smtp = Net::SMTP.new 'smtp.gmail.com', 587
33
+ smtp.enable_starttls
34
+ arr_of_rows = CSV.read(ARGV[0])
35
+ email_template = ARGV[1]
36
+ headers = arr_of_rows[0]
37
+ rows = arr_of_rows[1..]
38
+ template_contents = File.read(ARGV[1])
39
+ user_email = ARGV[2]
40
+ user_password = ARGV[3]
37
41
 
38
- renderer = ERB.new(template_contents)
39
- rows.each do |row|
40
- td = TemplateData.new(headers, row, template_contents)
41
- rendered_email = td.result
42
- puts rendered_email
43
- smtp.start('gmail.com',
44
- user_email, user_password, :plain) do |smtp|
45
- smtp.send_message rendered_email,
46
- user_email,
47
- td.instance_variable_get("@to_email")
42
+ renderer = ERB.new(template_contents)
43
+ rows.each do |row|
44
+ td = TemplateData.new(headers, row, template_contents)
45
+ rendered_email = td.result
46
+ puts rendered_email
47
+ smtp.start('gmail.com',
48
+ user_email, user_password, :plain) do |smtp|
49
+ smtp.send_message rendered_email,
50
+ user_email,
51
+ td.instance_variable_get("@to_email")
52
+ end
53
+ puts "-------------------------"
54
+ end
48
55
  end
49
- puts "-------------------------"
50
56
  end
51
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailmerge
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailmerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matan Silver