forked from nathanl/secret_santa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailer.rb
34 lines (27 loc) · 962 Bytes
/
emailer.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
require 'net/smtp'
class Emailer
attr_accessor :smtp_server, :domain, :account_address, :account_password, :port
def initialize(smtp_server, domain, account_address, account_password, port = 587)
self.smtp_server = smtp_server
self.domain = domain
self.account_address = account_address
self.account_password = account_password
self.port = port
end
def send(email)
email.from_address = account_address
if REALLY_SENDING
print "Mailing #{email.to_address}..."
smtp = Net::SMTP.new(smtp_server, port)
smtp.enable_starttls
smtp.start(domain, account_address, account_password, :login) do |smtp|
smtp.send_message(email.message, email.from_address, email.to_address)
end
print "sent!\n"
else
puts "**Testing; not really mailing anything**\nEmail would be as follows:\n\n"
puts email.message
puts "======"
end
end
end