Friday, 5 September 2008

Part 3: Integrating Asterisk with Exchange Server 2007 in a Unified Messaging Scenario

At this point, you should be seeing some SIP traffic between both servers. I’d also strongly recommend the use of network trace tool like WireShark.

Now, let's go back to Asterisk.

1. Simple configuration to reach Auto-attendant and Subscriber Access

First, we’re going to add in the Asterisk dial plan a context (we’re going to rather alter the “internal” context we create earlier to allow our test extensions to talk to each other)to reach the Exchange Auto-Attendant and Subscriber Access

Go to /etc/asterisk and open extensions.conf
Under the [internal] context, we’re adding the following at the bottom of what’s already there

exten => 8888,1,Dial(SIP/EXUM/8888)
exten => 9999,1,Dial(SIP/EXUM/9999)
exten => 8800,1,Dial(SIP/EXUM/8800)

Now save the changes and reload asterisk. To reload, log onto the Asterisk console and just type reload then press Enter

We can give it try. From either softphone, you’ve set up earlier, dial 8888 or 9999 to hear Exchange Server UM responds: “Welcome to the Microsoft Exchange Auto-Attendant” or when you dial 8800, you should something like “Welcome, you are connected to Microsoft Exchange. To access your mailbox, please enter your extension...”
These greetings can also be customized... check out one of the article by Microsoft included below,

If you can hear that, go have a beer or dance like no one’s watching, etc. Just make sure you not to pat yourself too much... we still got some work to do 

Should you wish to set up access from and to the Public Switch Telephone Network (PSTN), follow the same process as above.

2. Setup Exchange UM as the VoiceMail system for Asterisk’s local extensions

We’re now going to alter our prior dial plan between extensions to tell Asterisk what to do, in case the user/extension dialled doesn’t respond after x amount of time.

At this point our [internal] context in /etc/asterisk/extensions.conf should look like this
exten => 4455,1,Dial(SIP/4455)
exten => 4466,1,Dial(SIP/4466)

exten => 8888,1,Dial(SIP/EXUM/8888)
exten => 9999,1,Dial(SIP/EXUM/9999)
exten => 8800,1,Dial(SIP/EXUM/8800)

We’re going to be telling Asterisk to redirect the call to Exchange Subscriber Access (extension 8800) should the dialled party not be available. For Exchange Server to open the correct mailbox, we need to issue some diversion information.

A typos has been introduced. Correction ported on September 17, 2008
on the internal context below

4455,n,Dial(SIP/EXUM/2222 should actually read exten => 4455,n,Dial(SIP/EXUM/8800

Thanks to Pat for finding this one>

exten => 4455,1,Dial(SIP/4455,30)
exten => 4455,n,SIPAddHeader(Diversion: < tel:4455 >\;reason=noanswer\;screen=no\;privacy=off)
exten => 4455,n,Dial(SIP/EXUM/8800)
exten => 4455,n,Hangup

exten => 4466,1,Dial(SIP/4466,30)
exten => 4466,n,SIPAddHeader(Diversion: <tel:4466 >\;reason=noanswer\;screen=no\;privacy=off)
exten => 4466,n,Dial(SIP/EXUM/8800)
exten => 4466,n,Hangup

exten => 8888,1,Dial(SIP/EXUM/8888)
exten => 9999,1,Dial(SIP/EXUM/9999)
exten => 8800,1,Dial(SIP/EXUM/8800)

The called extension will ring 6 times before Asterisk forwards the call to Exchange to VoiceMail. The diversion line will replace ${EXTEN} with the correct extension (one could also specify the actually extension number but I think using variables makes it easier to implement and less likely to make mistakes)

3. Ensure Exchange UM can dial out via asterisk

Because we’ve previously set up the Exchange UM extension (i.e. [EXUM]) in Asterisk to use the [internal] context, we should be able to dial out any number the local extensions can. For example, you may call the auto-attendant and request to speak to “yourself”. Exchange should then call the phone extension via Asterisk and if no one picks up it returns to itself for voicemail.

Technical Resources:

Unified Messaging Cmdlets

Custom prompts for Exchange Server 2007 Unified Messaging

Asterisk HOW-TO tutorials and VoIP documents in general

Network tools


Pat said...

Great guide - I've got most of it working fine. One problem is with voicemail:

exten => 4466,n,Dial(SIP/EXUM/2222)

Where do I setup extn 2222?

Claude Tambu said...

Thanks Pat. That's a gotcha! 2222 should actually be 8800 as your Exchange UM Subsriber Access Number.

Two ways to resolve this problem [it's a mea culpa]:

1. You can add 2222 as another subscriber Access Number on your DialPlan

2. You could simply modify your Asterisk DialPlan by replacing 2222 with 8800

Thanks for catching this up and have a great one!


Pat said...

Hi Claude, I'm having a problem getting voicemail to work when I dial an extension. After the 6 rings, the call just drops. I can dial the Auto Attendant or my Mailbox directly and that works fine. Here is the log from Asterisk:

Connected to Asterisk 1.6.0-rc6 currently running on asterisk (pid = 2875)
Verbosity is at least 6
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
-- Executing [4466@from-internal:1] Dial("SIP/4455-0874dbd0", "SIP/4466,30") in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
-- Called 4466
-- SIP/4466-08755b00 is ringing
-- Nobody picked up in 30000 ms
-- Executing [4466@from-internal:2] SIPAddHeader("SIP/4455-0874dbd0", "Diversion:tel:4466\;reason=noanswer\;screen=no\;privacy=off") in new stack
-- Executing [4466@from-internal:3] Dial("SIP/4455-0874dbd0", "SIP/EXUM/8800") in new stack
== Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
-- Called EXUM/8800
-- SIP/EXUM-0874a4c8 is ringing
-- SIP/EXUM-0874a4c8 is circuit-busy
== Everyone is busy/congested at this time (1:0/1/0)
-- Executing [4466@from-internal:4] Hangup("SIP/4455-0874dbd0", "") in new stack

Claude Tambu said...

Thanks Pat.

Collect the Logs [Exchange UMCore and UMCallData] from your Windows box along with a network trace [wireshark does a great job] and send them to me to take a look

To see more info on your Application log, use Set-EventLogLevel cmdlet

An example is:
set-eventloglevel -id "MSExchange Unified Messaging\UMCore" -level expert

Also enable "MSExchange Unified Messaging\UMCallData" and "MSExchange Unified Messaging\UMClientAccess"

Keep me posted once you reproduce the issue and collect the data for analysis


Claude T.

Claude Tambu said...

Eureka, Pat!

I found the error. Diversion info sent by Asterisk are wrong.

I could repro your issue and Event ID 1109 and 1121 from UMCore tells you more by complaining you're sending the wrong extension number or something along these lines

Diversion info is wrong. It seems to be a machine mistake. Blogspot seemed to have remove the bracket inside (<>) around the {tel:4455} without the parenthesis.
. Your diversion info should then look like this without the parenthesis around tel:4455 argument. PLEASE replace parenthesis {} with bracket <>

exten => s,n,SIPAddHeader(Diversion:(tel:4455)\;reason=no-answer\;screen=no\;privacy=off)

I just need to figure out how not to have my <> stripped when posting in the article

Pat said...

Well done! I had seen that Asterisk was dialing the wrong exension and I had checked the syntax of the diversion, but failed to spot the error. Thanks for all your help.

Jon Webster said...

I've had a hard time understanding the whole subscriber access number concept. What I've found out, is that dialing 8800 generates an exchange event saying:

The user with extension "8800" on dial plan "Test Dialplan" is not enabled for Unified Messaging.

Further reading leads me to believe the ONLY place this information is used is in Outlook. Click Tools > Options > Voice Mail to see the subscriber acecss numbers listed as "Telephone access numbers"

Furthermore, the only extension that seems to really matter is for the auto attendant. Any other number sends me to the Welcome prompt and either UM knows who I am and asks for the mailbox PIN, or asks for the mailbox extension.

Not entering a valid UM extension does generate warnings though :).

This is an excellent series despite the typos (no-answer is still not spelled correctly in one location). Thanks!


Tim said...


thanks for writting these instruction. I've got everything working except dialing out from exchange.
The error is "handle_request_invite: Call from '' to extension '1234' rejected because extension not found."

Any ideas?


- T

Claude Tambu said...

Thanks Tim.

The error indicates you don't have an outbound route for the 1234.

In Asterisk, open your extensions.conf under /etc/asterisk and scroll to your [internal] context and make the appropriate modication.

For example, when/if I want to make outbound calls to the PSTN world either from my Asterisk-connected phones or from Exchange, I'll add the following route.


And since my Exchange UM extension and my Asterisk-connected phones are part of the "Internal" dialplan in Asterisk, I should be able to dial any number I specify in here as long as the route does go somewhere. Subsequently, you can add special routes as you wish.
Well, you can be creative from this point....

Please note the example assumes my Exchange UM DialPlan adds a 1 in front of a 10-digit number I dial out, etc.. ..

Hope that helps.



tim said...

Thanks for replying.

The extensions.conf works fine for the phones that are listed in sip.conf

In the Call from '' shouldn't the originating device be listed?

How does Asterisk know when exchange is passing the call to it rather than an unauthenticated device?


- T

Claude Tambu said...

Thanks Tim,

Exchange is also part of your sip.conf. Asterisk will use the info you set in [EXUM] to authenticate your Exchange.
"Type=friend" tells asterisk to trust Exchange with inbound and outbound calls. Exchange doesn't need to register, this is why you specified it's IP address or FQDN in the "host" parameters.


Another thing I add, is to enable debugging on Asterisk and set EventLogging level to Expert in Exchange so we can get more data

From Asterisk console(we're only enabling debugging on the Exchange extension):

sip set debug off
sip set debug peer EXUM

Now from the Exchange box, I'd add the following cmdlets.

set-eventloglevel -id "MSExchange Unified Messaging\UMCore" -level expert

Also enable "MSExchange Unified Messaging\UMCallData" and "MSExchange Unified Messaging\UMClientAccess"

And try again and let me know what you get...



tim said...

Got it....the debug info was really usefull.

As this was an extisting installation rather than a new one I didn't follow your instructions to the letter. I ended up with an exchange UM address that wasn't listed in sip.conf. Added the UM address and all works.

Now for
OCS 2007 - same error so hopefully the same solution - will try tomorrow.

Thanks for your help - this is a really great article.

- T

Claude Tambu said...

Glad I could help....

I'm currently working on a different project, but I can assist with OCS07 as well... pass me your OCS config/map and I'll see what I can do to assist you.

Well, as they say same issues should have same solutions.... :)



Anonymous said...

ngClaude: great series. Do you think you can put instructions for OCS 2007 here as well?

It seems these should work:

However, they may need this fix all the way at the bottom in the comments section:

Let me know if/when you'll put up OCS instructions in this guide.
Thank you!

phil said...

Great Stuff. with your help. I successfully integrated EXUM with Asterisk 1.6. However, EXUM fax is not working.the FAX CNG tone does not detected, so it's just treated as an missed call on the UM etc.

I tried modify the globcfg.mxl to different settings. None of them works.

Have you tried the exchange UM fax on Asterisk ? Thanks.

exten => 4455,n,SIPAddHeader(Diversion: < tel:4455 >\;reason=noanswer\;screen=no\;privacy=off)

should be:

exten => 4455,n,SIPAddHeader(Diversion: < tel:$EXTEN >\;reason=noanswer\;screen=no\;privacy=off)

Anonymous said...

Exchaneg attendant works but it doesn't recognize PIN.
How can I debug at the Exchange side?

Anonymous said...


I have pbx in a flash running asterisk 1.6 connected to my exchange 2007 box.

since I need to use Freepbx to edit the files how/where would I put the entries to have piaf redirect the call to exchange voicemail?

Thank you