# Creating Exchange mailBox via Ruby?

**URL:** <https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800>\
**Category:** Ruby\
**Created:** [December 8, 2005, 9:13pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800 "2005-12-08T21:13:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 8, 2005, 9:13pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/1 "2005-12-08T21:13:44Z")

</div>

Howdy!

I am setting up services that automagically provision a new portal user  
with things like filespace, and an Exchange mailbox. The filespace is  
easy, but I have not found any way to do the Exchange part. I have  
many vbscript examples, but that does not help me any if ruby cannot do  
what vbs can. So the question is:

Can Ruby interact with Exchange Information Stores, by creating  
mailboxes, changing mailbox properties and the like?

The vbs examples look like they use LDAP to connect and interact, but  
the methods that are used seem to be specific to vbs. Any one with any  
experience with this?

PS. I know that I can use vbs, but our setup would require the scripts  
to be run on a DC, and I would like to avoid that type of dependance.

---

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 8, 2005, 9:13pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/2 "2005-12-08T21:13:44Z")

</div>

I am looking into ADSI now… wondering if I can do almost the exact  
same stuff in ruby as what I found in vbs…

---

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 8, 2005, 9:13pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/3 "2005-12-08T21:13:45Z")

</div>

On 12/8/05, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> mailboxes, changing mailbox properties and the like?
> 
> The vbs examples look like they use LDAP to connect and interact, but  
> the methods that are used seem to be specific to vbs. Any one with any  
> experience with this?
> 
> PS. I know that I can use vbs, but our setup would require the scripts  
> to be run on a DC, and I would like to avoid that type of dependance.

Sure it can. Check out the Win32OLE library. It allows you to make all  
of  
the same calls you would in VBScript, in Ruby. I don’t have a link off  
hand, but if you used the ruby installer for win32 you’ve already got  
it.

---

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 9, 2005, 6:56pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/4 "2005-12-09T18:56:34Z")

</div>

On 12/8/05, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have found that I can do all the normal stuff, but interaction with  
> exchange is via CDOEXM.DLL, and I still have to see if WIn32OLE will do  
> that part as well. I can return all the user properties, and even the  
> HomeMDB which is the full path to the user’s mailbox, but I have not  
> had any success with CreateMailbox. I am thinking that I may have to  
> do it on the server for it to have access to the right DLL.

Really the only difference between performing this task in Ruby versus  
doing  
it in VBScript is that you get to use Ruby 🙂 Otherwise the same  
restrictions still apply. The COM Objects still have to reside locally  
unless you’re doing some DCOM mojo. To my knowledge though CDO has to  
be  
installed locally, but that doesn’t mean it has to be run from the  
Exchange  
server. I’ve seen automated Exchange creation run via a VBScript on a  
member server in the domain, as opposed to directly on the Exchange box.  
You just need to make sure you get CDO and all of that installed on the  
box  
you want to do the creation from.

---

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 13, 2005, 4:29pm UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/5 "2005-12-13T16:29:32Z")

</div>

I have the Exchange Management Tools installed, and I can do a little  
more than before. I can query and set attributes, but I cannot  
actually create a mailbox or set store defaults on existing mail boxws.  
It tells me it is an invalid method in both cases.

Here is the bit of code:

```
usr =WIN32OLE.connect("LDAP://CN=" + @login + cont)
	usr.CreateMailbox("LDAP://" + mBox )
	usr.EnableStoreDefaults = TRUE
	usr.AccountDisabled = FALSE
	usr.SetInfo
	usr.put "protocolsettings" , "POP3§0§1§4§ISO-8859-1§0§§§"
	usr.setinfo

```

I would really love to be able to do this in Ruby, since cscript takes  
so land to start it adds 10+ seconds to the operation.

---

<div class="post-metadata">

**Author:** ![tech.samaritan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@tech.samaritan](https://www.ruby-forum.com/u/tech.samaritan)\
**Post date:** [December 9, 2005, 12:13am UTC](https://www.ruby-forum.com/t/creating-exchange-mailbox-via-ruby/49800/6 "2005-12-09T00:13:28Z")

</div>

I have found that I can do all the normal stuff, but interaction with  
exchange is via CDOEXM.DLL, and I still have to see if WIn32OLE will do  
that part as well. I can return all the user properties, and even the  
HomeMDB which is the full path to the user’s mailbox, but I have not  
had any success with CreateMailbox. I am thinking that I may have to  
do it on the server for it to have access to the right DLL.
