Class: Lazylead::Exchange

Inherits:
Object
  • Object
show all
Includes:
Emailing
Defined in:
lib/lazylead/exchange.rb

Overview

TODO:

#/DEV Add support of symbols for options in order to use both notations like opts or opts.

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

Methods included from Emailing

#make_body, #split

Constructor Details

#initialize(log = Log::NOTHING, 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::NOTHING, salt = Salt.new("exchange_salt"), opts = ENV.to_h
)
  @log = log
  @salt = salt
  @opts = opts
end

Instance Method Details

#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
# 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: split("cc", opts)) if opts.key? "cc"
  cli.send_message msg
  @log.debug "Email was generated from #{opts} and send by #{__FILE__}. " \
             "Here is the body: #{html}"
end