module EWS::Mail

Mail module

Constants

ENDPOINT

Endpoint against which we want to run requests

NAMESPACES

Namespaces to add to the request

WSDL

URL of EWS WSDL

Public Class Methods

send(username:, password:, rcpts:, subject:, body:) click to toggle source

Send mail via EWS.

Senders is determined automatically by EWS based on your username.

Example

EWS::Mail.send(

username: '<USERNAME>',
password: '<PASSWORD>',
rcpts: '<RECIPIENT>',
subject: '<SUBJECT>',
body: '<PLAINTEXT-BODY>'

) EWS::Mail.send(

username: '<USERNAME>',
password: '<PASSWORD>',
rcpts: ['<RECIPIENT1>', '<RECIPIENT2>'],
subject: '<SUBJECT>',
body: '<PLAINTEXT-BODY>'

)

# File lib/ews_mail.rb, line 39
def self.send(username:, password:, rcpts:, subject:, body:)
        c = Savon.client({
                wsdl: WSDL,
                endpoint: ENDPOINT,
                basic_auth: [username, password],
                namespaces: NAMESPACES,
        })

        message = {
                'tns:Items' => {
                        't:Message' => {
                                't:Subject' => subject,
                                't:Body' => body,
                                't:ToRecipients' => {
                                        't:Mailbox' => [*rcpts].map do |v|
                                                { 't:EmailAddress' => v }
                                        end
                                },
                                attributes!: {
                                        't:Body' => { 'BodyType' => 'Text' }
                                }
                        }
                },
        }
        attributes = { 'MessageDisposition' => 'Send' }

        c.call(:create_item, message: message, attributes: attributes)
end