Module: Viewpoint::EWS::MessageAccessors

Includes:
Viewpoint::EWS
Included in:
Viewpoint::EWSClient
Defined in:
lib/ews/message_accessors.rb

Overview

This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.

Copyright © 2011 Dan Wanek <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Constant Summary

Constants included from Viewpoint::EWS

ConnectingSID

Instance Attribute Summary

Attributes included from Viewpoint::EWS

#logger

Instance Method Summary collapse

Methods included from Viewpoint::EWS

#remove_impersonation, root_logger, #set_impersonation

Instance Method Details

#draft_message(opts = {}, &block) ⇒ Object

See #send_message for options



71
72
73
# File 'lib/ews/message_accessors.rb', line 71

def draft_message(opts = {}, &block)
  send_message opts.merge(draft: true), &block
end

#send_message(opts = {}) {|msg| ... } ⇒ Message, Boolean

TODO:

Finish ItemAttachments

Send an E-mail message

Parameters:

  • opts (Hash) (defaults to: {})

    A Hash with message params

Options Hash (opts):

  • :subject (String)

    The message subject

  • :body (String)

    The message body

  • :to_recipients (Array)

    An array of e-mail addresses to send to

  • :cc_recipients (Array)

    An array of e-mail addresses to send to

  • :bcc_recipients (Array)

    An array of e-mail addresses to send to

  • :extended_properties (Array)

    An array of extended properties

    {epros, value: <val>}

    or values: [<val>, <val>]

  • :draft (Boolean)

    if true it will save to the draft folder without sending the message.

  • saved_item_folder_id (String, Symbol, Hash)

    Either a FolderId(String) or a DistinguishedFolderId(Symbol). You can also pass a Hash in the form: <fold_id>, change_key: <change_key>

  • :file_attachments (Array<File>)

    an Array of File or Tempfile objects

  • :inline_attachments (Array<File>)

    an Array of Inline File or Tempfile objects

Yields:

  • (msg)

Returns:

  • (Message, Boolean)

    Returns true if the message is sent, false if nothing is returned from EWS or if draft is true it will return the Message object. Finally, if something goes wrong, it raises an error with a message stating why the e-mail could not be sent.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ews/message_accessors.rb', line 43

def send_message(opts = {}, &block)
  msg = Template::Message.new opts.clone
  yield msg if block_given?
  if msg.has_attachments?
    draft = msg.draft
    msg.draft = true
    resp = parse_create_item(ews.create_item(msg.to_ews))
    msg.file_attachments.each do |f|
      next unless f.kind_of?(File) or f.kind_of?(Tempfile)
      resp.add_file_attachment(f)
    end
    msg.inline_attachments.each do |f|
      next unless f.kind_of?(File) or f.kind_of?(Tempfile)
      resp.add_inline_attachment(f)
    end
    if draft
      resp.submit_attachments!
      resp
    else
      resp.submit!
    end
  else
    resp = ews.create_item(msg.to_ews)
    resp.response_messages ?  parse_create_item(resp) : false
  end
end