Class: Lazylead::Exchange
- Inherits:
-
Object
- Object
- Lazylead::Exchange
- Includes:
- Emailing
- 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
- #add_attachments(msg, opts) ⇒ Object
- #close_attachments(msg) ⇒ Object
-
#initialize(log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h) ⇒ Exchange
constructor
A new instance of Exchange.
-
#send(opts) ⇒ Object
Send an email.
Methods included from Emailing
Constructor Details
#initialize(log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h) ⇒ Exchange
Returns a new instance of Exchange.
44 45 46 47 48 49 50 |
# File 'lib/lazylead/exchange.rb', line 44 def initialize( log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h ) @log = log @salt = salt @opts = opts end |
Instance Method Details
#add_attachments(msg, opts) ⇒ Object
72 73 74 75 76 |
# File 'lib/lazylead/exchange.rb', line 72 def (msg, opts) return unless opts.key? "attachments" files = split("attachments", opts).map { |f| File.open(f, "r") } msg[:file_attachments] = files end |
#close_attachments(msg) ⇒ Object
78 79 80 81 |
# File 'lib/lazylead/exchange.rb', line 78 def (msg) return if msg[:file_attachments].nil? || msg[:file_attachments].empty? msg[:file_attachments].each(&:close) end |
#send(opts) ⇒ Object
Send an email.
- :opts
-
the mail configuration like from, cc, subject, template.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/lazylead/exchange.rb', line 54 def send(opts) to = opts["to"] || opts[:to] to = [to] unless to.is_a? Array html = make_body(opts) msg = { subject: opts["subject"], body: html, body_type: "HTML", to_recipients: to } msg.update(cc_recipients: opts["cc"]) if opts.key? "cc" (msg, opts) cli. msg msg @log.debug "Email was generated from #{opts} and send by #{__FILE__}. " \ "Here is the body: #{html}" end |