Class: GmailSender
- Inherits:
-
Object
- Object
- GmailSender
- Defined in:
- lib/gmail_sender.rb
Constant Summary collapse
- ATTACHMENT_READ_PORTION =
you may change this, but must be multiply to 3
150360
Instance Method Summary collapse
- #attach(file) ⇒ Object
-
#initialize(user, password, domain = "gmail.com") ⇒ GmailSender
constructor
A new instance of GmailSender.
- #send(to, subject = "", content = "") ⇒ Object
- #set_message_stream(msg_stream, to, subject, content) ⇒ Object
Constructor Details
#initialize(user, password, domain = "gmail.com") ⇒ GmailSender
Returns a new instance of GmailSender.
8 9 10 11 12 13 14 15 16 |
# File 'lib/gmail_sender.rb', line 8 def initialize(user, password, domain="gmail.com") @sender_domain = domain @sender_password = password @sender_email = "#{user}@#{domain}" @net_smtp = Net::SMTP.new("smtp.gmail.com", 587) @net_smtp.enable_starttls @attachments = [] @boundary = rand(2**256).to_s(16) end |
Instance Method Details
#attach(file) ⇒ Object
18 19 20 |
# File 'lib/gmail_sender.rb', line 18 def attach(file) @attachments << file if File.exist?(file) end |
#send(to, subject = "", content = "") ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/gmail_sender.rb', line 22 def send(to, subject = "", content = "") @net_smtp.start(@sender_domain, @sender_email, @sender_password, :plain) do |smtp| smtp.(@sender_email, [to]) do |msg_stream| (msg_stream, to, subject, content) end end end |
#set_message_stream(msg_stream, to, subject, content) ⇒ Object
30 31 32 33 34 |
# File 'lib/gmail_sender.rb', line 30 def (msg_stream, to, subject, content) set_headers(msg_stream, to, subject) set_content(msg_stream, content) (msg_stream) end |