RExchange -- A simple Ruby wrapper around Microsoft Exchange
RExchange is a pure ruby wrapper for the Microsoft Exchange Server WebDAV API
Things you should know
* Requires Ruby 1.8.4 (or later, for the extended WebDAV support in the net/http library)
* RExchange is cross-platform compatible, being written in pure Ruby
* Kiwi fruits are packed with vitamins
Why should you use RExchange
* It makes interacting with Exchange simple
* It was written for a real application, and does real work reliably day in and day out
Example
# We pass our uri (pointing directly to a mailbox), a username, and a password to RExchange::open
# to create a RExchange::Session. Notice that we escape the "\" in our username.
RExchange::open('https://example.com/exchange/admin/', 'mydomain\\admin', 'secret') do |mailbox|
# The block parameter ("mailbox" in this case) is actually the Session itself.
# You can refer to folders by chaining them as method calls. "inbox" in this case
# isn't a defined method for Session, but part of the DSL to refer to folder names.
# Each folder name returns a RExchange::Folder. The folder is Enumerable, allowing
# iteration over the items in the folder, depending on the DAV:content-class of
# the folder.
mailbox.inbox.each do |message|
# The "message" block parameter is a RExchange::Message object. You have access to
# several attributes of the message, including: href, from, to, message_id, date,
# importance, has_attachment? and body.
p message.subject
# The RExchange::Message#move_to method moves the message to another folder, in this
# case, an "archive" folder off of the inbox.
message.move_to mailbox.inbox.archive
end
# Folder names are "normalized", replacing dashes and spaces with underscores,
# squeezing out multiple underscores in a row, and downcasing the whole thing.
# So a folder name such as "My Very-long Folder Name" would look like:
mailbox.my_very_long_folder_name
# The Enumerable mixin gives us an Folder#entries method in case we just want to
# return an array.
messages = mailbox.inbox.entries
# Other methods, like Enumerable#map and Enumerable#sort_by let us manipulate
# the Folder in fun ways:
puts mailbox.contacts.sort_by { |contact| contact.first_name }.map do |contact|
Kommentare
Link hinzufügen
als Spam markieren





Jobportal für IT und Webentwicklung