Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
/ Ruby-EWS Public archive

Simple example of accessing Microsoft Exchange Web Services via Ruby

Notifications You must be signed in to change notification settings

lusis/Ruby-EWS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In this directory is some sample code I wrote for accessing a Microsoft Exchange Server via Exchange Web Services from ruby.
Motivation
I use mutt as my email client at work. It's fast and I like it. While I'm on the VPN, I can perform lookups just fine using the LDAP server on our AD servers.

However my problem cropped up while I was flying back from Michigan on Airtran using the in-flight wireless. I was checking and sending email but the connection kept dropping and my VPN connection kept dying.

We don't have LDAP exposed to the internet so I couldn't just stay off the VPN since I needed to lookup addresses. That's where this comes in.

I needed to be able to perform lookups for email addresses while not on the VPN.
Required gems:

    * soap4r
    * rubyntlm

Files:

    * default.rb|defaultDriver.rb|defaultMappingRegistry.rb
    * - These files are generated by wsdl2ruby.rb from the soap4r gem. Don't mess with them if you expect this to work. Either Microsoft or wsdl2ruby are to blame but they had to be massaged to work. ewslookup.rb
    * - ruby class ews.rb
      - sample script to do a lookup against the exchange server 

Usage:
If you want to use the sample script, feel free. Edit the username,password and endpoint variables at the top. Results are returned as an Array with an Array for each result/member.
GAL Lookup

./ews.rb -g go

will perform a lookup against the GAL and return and Contact, Mailbox or Distribution List that matches.
Example Output:

[["Bob Gold", "bgold@mydomain.com", "Mailbox"],
 ["googleusers", "googleusers@mydomain.com", "PublicDL"],
 ["Golden Ticket Foods", "orders@externaldomain.com", "Contact"]]

DL Expansion

./ews.rb -l googleusers@mydomain.com
./ews.rb -l googleusers

Will return a list of members in that Distribution List. The EWS call for distribution lists behaves differently than the lookup call. You MUST type the exact name or SMTP address associated with the DL.
Example Output:

[["Jack Smith", "jsmith@mydomain.com"],
 ["Bob Gold", "bgold@mydomain.com"],
 ["Frank White", "fwhite@mydomain.com"]]

Gotchas:
The ExpandDL call to EWS requires the exact email address or name of the distribution list to get results. That's how MS did it. I plan on fixing it in another little version to do the following (in case you want to do it yourself):

    if no results are found for the expandDL call:
        perform a resolveNames call for the lookup passed and get any PublicDL results that match
        redo the expandDL call with the proper name/email address
    else "No results found" for real this time

Future
I'll probably write a few more classes to ineract with things like calendars and public folders allthough I honestly don't use them much. 

About

Simple example of accessing Microsoft Exchange Web Services via Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages