Class: ChatworkBridge::Notifiers::EmailNotifier
- Inherits:
-
Object
- Object
- ChatworkBridge::Notifiers::EmailNotifier
- Defined in:
- lib/chatwork_bridge/notifiers/email_notifier.rb
Instance Attribute Summary collapse
-
#enable_tls ⇒ Object
Returns the value of attribute enable_tls.
-
#from ⇒ Object
Returns the value of attribute from.
-
#smtp_host ⇒ Object
Returns the value of attribute smtp_host.
-
#smtp_password ⇒ Object
Returns the value of attribute smtp_password.
-
#smtp_port ⇒ Object
Returns the value of attribute smtp_port.
-
#smtp_user ⇒ Object
Returns the value of attribute smtp_user.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
Instance Attribute Details
#enable_tls ⇒ Object
Returns the value of attribute enable_tls.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def enable_tls @enable_tls end |
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def from @from end |
#smtp_host ⇒ Object
Returns the value of attribute smtp_host.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def smtp_host @smtp_host end |
#smtp_password ⇒ Object
Returns the value of attribute smtp_password.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def smtp_password @smtp_password end |
#smtp_port ⇒ Object
Returns the value of attribute smtp_port.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def smtp_port @smtp_port end |
#smtp_user ⇒ Object
Returns the value of attribute smtp_user.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def smtp_user @smtp_user end |
#to ⇒ Object
Returns the value of attribute to.
8 9 10 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8 def to @to end |
Instance Method Details
#notify(notification) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 10 def notify(notification) send_email( "[ChatWork] #{notification['room_name']}", notification['content'] ) $logger.info "Email sent to #{self.to}" end |
#send_email(subject, body) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 18 def send_email(subject, body) to_addr = self.to from_addr = self.from mail = Mail.new do to to_addr from from_addr subject subject body body end mail.charset = 'utf-8' smtp = Net::SMTP.new(self.smtp_host, self.smtp_port) smtp.enable_starttls if self.enable_tls smtp.start(self.smtp_host, self.smtp_user, self.smtp_password, :login) do smtp.(mail.encoded, mail.from, mail.to) end end |