Class: Lazylead::Exchange
- Inherits:
-
Object
- Object
- Lazylead::Exchange
- Defined in:
- lib/lazylead/exchange.rb
Overview
A postman to send emails to the Microsoft Exchange server.
- Author
-
Yurii Dubinka ([email protected])
- Copyright
-
Copyright © 2019-2020 Yurii Dubinka
- License
-
MIT
Instance Method Summary collapse
-
#initialize(log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h) ⇒ Exchange
constructor
A new instance of Exchange.
- #make_msg(opts) ⇒ Object
-
#send(opts) ⇒ Object
Send an email.
Constructor Details
#initialize(log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h) ⇒ Exchange
Returns a new instance of Exchange.
42 43 44 45 46 47 48 |
# File 'lib/lazylead/exchange.rb', line 42 def initialize( log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h ) @log = log @salt = salt @opts = opts end |
Instance Method Details
#make_msg(opts) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/lazylead/exchange.rb', line 64 def make_msg(opts) msg = { subject: opts["subject"], body: opts.msg_body, body_type: "HTML", to_recipients: opts.msg_to } files = opts..map { |f| File.open(f, "r") } msg[:file_attachments] = files unless files.empty? msg[:cc_recipients] = opts["cc"] if opts.key? "cc" msg end |
#send(opts) ⇒ Object
Send an email.
- :opts
-
the mail configuration like from, cc, subject, template.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lazylead/exchange.rb', line 52 def send(opts) if opts.msg_to.empty? @log.warn "ll-012: Email can't be sent to '#{opts.msg_to}," \ " more: '#{opts}'" else msg = make_msg opts cli. msg msg[:file_attachments].each(&:close) unless opts..empty? @log.debug "#{__FILE__} sent '#{opts['subject']}' to '#{opts.msg_to}'." end end |