-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsend_emails.rb
47 lines (38 loc) · 1.41 KB
/
send_emails.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "base64"
require "mailgun"
# recipients is an array of name email pairs
# [
# ["Daniel", "[email protected]"]
# ...
# ]
def send_emails(recipients)
recipients.each do |person|
others = (recipients - [person])
others_names = others.map do |person|
"#{person.first} (#{person.last})"
end.join " and "
# TODO: Can't get multi-way reply-to working
# this will cover it for 90% of the time
reply_to = others.first.last
email = person.last
message = {
:text => "This week you're meeting with #{others_names}.
Get to know your coworkers. Meet up in person or over a hangout, grab a coffee, and chat. Plan to meet for about half an hour, reach out to your person and schedule a time that works for both of you.
Enjoy!
P.S. Email [email protected] with questions, comments or suggestions about CoffeeTime.
- Mr. CoffeeTime",
:subject => "CoffeeTime with #{others_names}",
:from => "Daniel X <[email protected]>",
:to => "#{person.first} <#{person.last}>",
:"h:Reply-To" => reply_to
}
mailgun = Mailgun::Client.new ENV['MAILGUN_API_KEY']
sending_domain = ENV['MAILGUN_DOMAIN']
begin
result = mailgun.send_message sending_domain, message
rescue => e
# $REDIS.rpush "retries", {person: person, others_names: others_names}.inspect
puts "An error occurred sending email: #{e.class} - #{e.message}"
end
end
end