Module: EWS::Mail

Defined in:
lib/ews_mail.rb

Constant Summary collapse

WSDL =
'https://outlook.office365.com/EWS/Services.wsdl'
ENDPOINT =
'https://outlook.office365.com/EWS/Exchange.asmx'
NAMESPACES =
{
	'xmlns:t' =>
		'http://schemas.microsoft.com/exchange/services/2006/types'
}

Class Method Summary collapse

Class Method Details

.send(username:, password:, rcpts:, subject:, body:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ews_mail.rb', line 13

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