Class: ChatworkBridge::Notifiers::EmailNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/chatwork_bridge/notifiers/email_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enable_tlsObject

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

#fromObject

Returns the value of attribute from.



8
9
10
# File 'lib/chatwork_bridge/notifiers/email_notifier.rb', line 8

def from
  @from
end

#smtp_hostObject

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_passwordObject

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_portObject

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_userObject

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

#toObject

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.send_message(mail.encoded, mail.from, mail.to)
  end
end