Tuesday, November 28, 2006

Instructions on how to connect Asterisk to Microsoft Exchange 2007 for Unified Messaging

UPDATE AGAIN: There are MUCH better instructions for this at http://blog.lithiumblue.com/2007/04/accessing-exchange-2007-unified_29.html I recommend you take a look at Ryans step-by-step. My guide is nearly 6 months old now, and there are some things that Ryan has done that make it a lot easier to set up than mine. Well done Ryan :-)

*UPDATE:- I will not be adding to the following information any more. I have almost finished a new installation, linking Asterisk with Exchange, which copes with all the Exchange Unified Messaging features such as fax, OVA and answering machine. This will appear on this page in the very near future

Please note that the instructions do not cover the installation of the sipx and asterisk servers, only the configuration of them. I originally used the VMWare community images of trixbox (asterisk with loads of add-ons) and SIPX. Since then, I have installed a stand alone trixbox (iso image from www.trixbox.org). I'm still having problems with CAPI (Fritz! PCI installed in my Asterisk server (cos it was cheap - €30 for two lines is a nice price for testing) so I'll probably end up installing it again using SUSE 9.3 (cos there's a better CAPI driver for SUSE from avm). However, this does not affect how it works. I can dial in via a normal telephone, or I can use a SIP phone connected to either the Asterisk or the SIPX machine and access Exchange UM.

If anybody would like even more detailed instructions (i.e. screenshots, config files, etc.) please let me know. Either add a comment here, or write to me at alginald at gmx dot de. No spam please, I'm vegetarian.

What this document covers:-
1) When somebody connected to the asterisk dials 666666, the call should be forwarded to the Exchange 2007 Auto attendant, whereby the caller can choose to contact somebody directly, or leave a message for them (voice mail)
2) When somebody connected to the asterisk dials 55, the call should be forwarded to the Exchange 2007 Subscription number, whereby the caller can enter their mailbox number, and their pin number for access to their mailbox via Outlook Voice Access

What is not working:-

1) The caller ID is currently not passed correctly from sipx to Exchange, so all Voice messages originate from "anonymous" at the moment

2) Dialling from Exchange 2007 out. This is quite easy to configure, and I have had it working, I have even included some of the instructions, but have not fully tested it

Initial installation
Install Exchange 2007 with the Unified Messaging role
Install Asterisk (I installed , from www.trixbox.org and the trixbox VMWare image, both worked fine)
Install SIPX. (I used the VMWare image from the VMWare community download pages)
The rest of this document assumes that you have downloaded and are using the VMWare images of trixbox and sipx.
The following computers are used...
asterisk1.local. (TRIXBOX)
IP address
testorg.int (SIPX)
IP address
e2k7srv2.testorg.int (Exchange / AD / DNS)
IP address
(I know that the sipx box has got the same name as my domain, that was not done on purpose, a different name can be used if you want)

********************************* START OF EXCHANGE 2007 CONFIGURATION ******************************
What to configure on the Exchange 2007 server
1) Create a new UM Dial Plan....
new-UMDialPlan -Name:'DialPlan6' -NumberOfDigitsInExtension:'6'
2) Add the subscription number 5 to the UM Dial Plan
In the Exchange Management Console,click on Organization Configuration / Unified Messaging / DialPlan6
On the second tab, Subscription Access, add the subscription number "5"
3) Create a new UM IP Gateway...
new-UMIPGateway -Name:'SIPX' -Address:'' -UMDialPlan:'DialPlan6'
(If you do not want to dial out using Exchange, open the properties page for the IP gateway, and deselect the "Allow outgoing calls".)
4) Create two new hunt groups for the UM IP Gateway.....
new-UMHuntGroup -Name:'Hunt5' -IPGateway:SIPX -UMDialPlan:'DialPlan6' -PilotIdentifier:'5'
new-UMHuntGroup -Name:'Hunt6' -IPGateway:SIPX -UMDialPlan:'DialPlan6' -PilotIdentifier:'6'
5) Create a new Auto Attendant.....
new-UMAutoAttendant -Name:'AA6' -UMDialPlan:'DialPlan6 -PilotIdentifierList:'666666' -Status:'Enabled' -SpeechEnabled:$true
6) Once the Auto Attendant has been created, edit the properties, and on the features tab, select
Allow caller to transfer to users
Allow callers to send voice mail
Callers can contact anybody in the Global Address List
Allow transfer to operator during business hours
Allow transfer to operator after business hours
(You don't have to configure all of these if you don't want to, but you should have at least the "allow callers to send voice mail and the "anybody in the GAL" set.)
7) Add the Dial Plan (DialPlan6) to the Exchange server
In the Exchange Management Console navigate to Server Configuration / Unified Messaging. Click on the e2k7srv2 server in the main pane with the right mouse button and click on properties. On the UM Settings page, add the dial plan to the list.
(There's probably a management shell command for this, but I used the GOOEY ;-))
8) Create a new UM Mailbox Policy...
new-UMMailboxPolicy -Name:'UMMailPolicy6' -UMDialPlan:'DialPlan6'
9) Enable Unified messaging for one or more test users. I gave Mickey Mouse the extension 777777 and Donald Duck the extension 777778.
********************************* END OF EXCHANGE 2007 CONFIGURATION ******************************
************************************ START OF ASTERISK CONFIGURATION ********************************
Now to configure the asterisk....
There are two ways of configuring the asterisk, you can edit the files via putty or the local console, or you can use the trixbox interface.
************************ start of asterisk configuration using trixbox ************
If you want to configure Asterisk using the Web Interface from trixbox, do the following
1) Connect to the server with a web browser (in my case
2) Click on System Administration and logon with user maint and password password (or whatever)
3) Click on FreePBX (you could also go directly to the page instead)
4) In the new browser window (FreePBX), click on setup
5) Click on TRUNKS
6) Click on Add Sip Trunk
7) Set the following
Outbound Caller ID:6
Dial Rules:6666+6XXXXXXX
Outbound Dial Prefix:66

8) Thats the first trunk. Now do the same again for the second one...
Outbound Caller ID:5
Dial Rules:5555+5XXXXXXX
Outbound Dial Prefix:55
Peer Details:

9) Click on outbound routes
10) Click on Add Route
11) Create a route with the following settings
name:1 6_SipX
Trunk Sequence:SIP/SIPX

12) Create a second route with the following settings
Trunk Sequence:SIP/SIPX2

13) If you want to add a softphone extension for testing do the following
14) Click on extensions
15) Click on SIP and set the following
Display Name:Yourname
Extension Number:200
Direct DID:200

************ End of Asterisk configuration using trixbox ******************

If you don't want to use the trixbox front end, just edit the files in the /etc/asterisk directory, do the following...
What we need to configure is two Dial Plans and two trunks.
Here is my /etc/asterisk/extensions_additional.conf, which is used for the dial plans
;********************** Start of extensions_additional.conf ***************************
OUTCID_1 = 6
FAX_RX_FROM = freepbx@gmail.com
OUTCID_3 = 5

;end of [globals]
include => app-cf-busy-off-custom

include => ext-did-direct-custom
exten => 200,1,Set(FROM_DID=200)
exten => 200,n,Goto(from-did-direct,200,1)
; end of [ext-did-direct]

include => ext-local-custom
exten => 200,1,Macro(exten-vm,novm,200)
exten => 200,hint,SIP/200
; end of [ext-local]

include => outbound-allroutes-custom
include => outrt-001-1 6_SipX
include => outrt-002-5_SipX2
exten => foo,1,Noop(bar)
; end of [outbound-allroutes]

[outrt-001-1 6_SipX]
include => outrt-001-1 6_SipX-custom
exten => _6.,1,Macro(dialout-trunk,1,${EXTEN},,)
exten => _6.,n,Macro(outisbusy,)
; end of [outrt-001-1 6_SipX]

include => outrt-002-5_SipX2-custom
exten => _5.,1,Macro(dialout-trunk,3,${EXTEN},,)
exten => _5.,n,Macro(outisbusy,)
; end of [outrt-002-5_SipX2]

include => from-internal-additional-custom
include => app-cf-busy-off
include => app-cf-busy-off-any
include => app-cf-busy-on
include => app-cf-off
include => app-cf-off-any
include => app-cf-on
include => app-cf-unavailable-off
include => app-cf-unavailable-on
include => app-userlogonoff
include => app-zapbarge
include => ext-test
include => ext-local
include => outbound-allroutes
exten => h,1,Hangup
; end of [from-internal-additional]

;********************** end of extensions_additional.conf ***************************
(p.s. make sure there is an entry in the extensions.conf called #include extensions_addtional.conf)
I have left some of this file out, so you may want to edit the existing one, and just add the bits above. (You can connect to the asterisk box with SSH to edit files, or log on locally)
Also note that trunk 2 in the above configuration is my capi in card. you might want to remove this from here if you don't want to capi it.

Here is my /etc/asterisk/sip_additional.conf
;********************** start of sip_additional.conf ***************************
callerid=Alan <200>


;********************** end of sip_additional.conf ***************************
(p.s. make sure there is an entry in the sip.conf called #include sip_additional.conf)

Please note that the first entry, [200] is a test phone that I configured, for the user Alan
The [SIPX] and [SIPX2] are the two connections to the SIPX server. the secret is the password for root on the SIPX machine, although AFAIK, you don't need it

Here is the file /etc/asterisk/localprefixes.conf
;********************** start of localprefixes.conf ***************************


;********************** end of localprefixes.conf ***************************

************************************** END OF ASTERISK CONFIGURATION ********************************
I recommend using the trixbox/freepbx web interface unless you're a dab hand with vi.

**************************************** START OF SIPX CONFIGURATION ***********************************
Finally, we need the SIPX configuration
As you probably read at the beginning, I used the VMWare image. If you use the same onem I recommend changing the ip address, server name and dns server manually.
Once you have the necessary information, connect to the sipx server's web server via web browser (in my case
Click on configuration, accept the goofy SSL, and enter the username and password (in the VMWare image case, superadmin, no password)
Click on gateways, and then Add Gateway. Give a name for the gateway (i.e. ToMXS) and enter the IP address and the MAC address from the Exchange Server, and select unmanaged gateway
Now we need the two dial plans
First, for Voice Mail...
Click on Dial Plans
Click on Add Dial Rule
Click on Enabled
Give it a name
In Dialed Numbers, add 6 with "any number of digits"
In Resulting call, enter 666666 with nodigits
Add the gateway defined above for the route
Second, for Outlook Voice Access
Click on Dial Plans
Click on Add Dial Rule
Clickon Enabled
Give it a name
In Dialed Numbers add 5 with "any number of digits"
In Resulting Call, enter 5 with nodigits
Add the gateway defined above for the route
Move these dial plans to the top of the list (Select the dial plan and click slowly but surely on Move UP)
Make sure they are enabled, and then click on Dial Plan Activation, "Activate"
That's all there is.
**************************************** END OF SIPX CONFIGURATION ***********************************

If you want to dial back to the Asterisk, add an additional Gateway and a Dial Plan on the SIPX box to point to the Asterisk Box, and just configure the Exchange box to use the correct prefix.
What to do if it doesn't work?
Log into the asterisk server and use the command "asterisk -r -dddddddddd -vvvvvvvvvv"
Check the asterisk logs in the /var/log/asterisk directory
Set the Exchange UM logging to 7 via the registry
Write to me @ alginald at gmx dot de, or post a comment :-)

great stuff. why do you need sipx? couldn't asterisk do all the call routing?
Asterisk normally only does SIP over UDP, and Exchange only does SIP over TCP, therefore the SIPX handles the routing as it can do both. I did once see a draft of SIP/TCP for Asterisk, but not a lot of information.
Great instuction !!! It was a big help for me. Actually this is the only actual instruction on how to get asterisk working with UM Exchange 2007
More instructions with screenshots would rock the Casba! But I'm amazed and impressed that you've gone to the trouble you already have in documenting and posting the configuration procedure. It will certainly help me to take my asterisk system to the next level. All I've used until now as far as mail client integration has been asttapi and the voicemail by email function.

This is what open source is all about.

I salute you sir!
Alginald... Thanks so much for your efforts. We saw your update that you were almost finished with a new installation. Do you have ANY idea when you might be posting the new instructions? We have tried the original instructions and couldn't make them work. We are an IT services company and want to offer this to our customers and we have a booth at a tradeshow we are attending soon and would like to demonstrate this if at all possible. Thanks again for your efforts
Hi Alginald,

Awesome instructions, this helped me a lot with our UM setup, however, I'm wanting to take it to the next level. Do you know how I can set up the answer machine part, so that if some random person dials a number (that exists in UM) and they don't pickup, it would go to the "Please leave a message" prompt and drop the voice mail message in the mailbox of the person dialed?

My email address is nick[at]datanet|co|nz if you would like to contact me (we could talk more about the setup?).


Hi Alginald and others,

I've put together a set of instructions based on the ones here, including some screen shots and some troubleshooting info.


Alginald, i'm happy to add/improve on this if you have anything to add.


I have added information to fix the sipX-Exchange timeout issue if you are interested, once again at http://blog.lithiumblue.com/2007/04/accessing-exchange-2007-unified_29.html
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?