Class: Gmail::Emailer
- Inherits:
-
Object
- Object
- Gmail::Emailer
- Defined in:
- lib/gmail_sender.rb
Instance Method Summary collapse
- #create_message(to, subject, content) ⇒ Object
-
#initialize(user, password, domain = "gmail.com") ⇒ Emailer
constructor
A new instance of Emailer.
- #send(to, subject, content) ⇒ Object
Constructor Details
#initialize(user, password, domain = "gmail.com") ⇒ Emailer
Returns a new instance of Emailer.
5 6 7 8 9 10 11 |
# File 'lib/gmail_sender.rb', line 5 def initialize(user, password, domain="gmail.com") @domain = domain @password = password @user = "#{user}@#{domain}" @net_smtp = Net::SMTP.new("smtp.gmail.com", 587) @net_smtp.enable_starttls end |
Instance Method Details
#create_message(to, subject, content) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/gmail_sender.rb', line 20 def (to, subject, content) <<MSG From: #@gmail_user To: #{to} Subject: #{subject} #{content} MSG end |
#send(to, subject, content) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/gmail_sender.rb', line 13 def send(to, subject, content) @net_smtp.start(@domain, @user, @password, :plain) do |smtp| msg = (to, subject, content) smtp.(msg, @user, to) end end |