rjaiswal
Active Member
- Joined
- May 24, 2013
- Messages
- 438
- Reaction score
- 58
Hello all,
After learning so much from this site, I thought I'd give a little back. I've scoured the interwebs, looking for tutorials that would allow me to hookup asterisk to Exchange UM. I had it running fairly reliably on my PiaF purple install, but that crashed and burned. So, I decided to setup Exchange 2013 and PiaF Green. This is what I needed to do get it to work. Credit goes to all authors of the various blogs and forum posts. This is NOT for the faint of heart. One needs the ability to figure out gremlins, and such when setting this up. These instructions worked for me, and they could, very well, work for you. I will try to look at the thread once a day to answer questions, however, I do have to make a living, so please be patient with me in responding.
First off, you need to tell Asterisk to use TCP in addition to UDP for SIP communication. Micro$oft, in their infinite wisdom, decided to only allow TCP SIP communication on all of their Unified Communications applications, which includes Exchange. To do this, you need to add 2 fields to the "Other SIP Settings" area of the "Asterisk SIP Settings" Menu.
After adding the 2 fields, enter the following settings to enable TCP communication:
Once that is completed, the next step is to configure a Trunk that will be used to communicate between Exchange and PiaF (For Exchange 2013, you need to create 2 Trunks one that uses Port 5065, and one that uses Port 5067)
Now, we need to create an outbound route so that we can allow internal communication between Asterisk And Exchange. This is what needs to be added to the Outbound Route. For your trunk sequence, only add the newly created trunk that we just made. (For Exchange 2013, you would also add the 2nd trunk.)
My Dial Patterns might look weird, but it's normal for this route. You need to enter every IVR, that you've configured in Exchange as a separate dial pattern. You also need to create a Misc Destination for EVERY Exchange hosted IVR as well as the "pilot identifier" to access voicemail. The default is 999. In my example I use 999 to access voicemail, 401 to access my first IVR, and 402 to access my second IVR.
Configure Asterisk to Forward Calls to Exchange Unified Messaging for Voicemail
Asterisk defaults to forwarding calls to its own voicemail extensions and so edits need to be made to the extensions.conf ( or linked files if using FreePBX) to route calls to the Exchange Server for voicemail.
Since we are using FreePBX, we need to edit /etc/asterisk/extensions_override_freepbx.conf.
The next section is copied from a blog post from Brian Reid, of C7 Solutions.
The first change is to copy the [macro-vm] section from /etc/asterisk/extensions_additional.conf into /etc/asterisk/extensions_override_freepbx.conf. [macro-vm] is approx 150 lines long and ends with “;--== end of [macro-vm] ==--;”.
Then we need to make some changes and additions to the macro-vm section. The first set of changes will comment out the code the directs calls to Asterisk voicemail and the additional lines will dial the Exchange Server trunks and add SIP Diversion headers so that Exchange knows which mailbox to answer the call for.
So first, locate the following lines and comment them out. The numbers in brackets at the start are the approx. location in extensions_override_freepbx.conf where you will find the line:
Each of the above lines can be commented out by placing a semi-colon ( at the start of the line.
Return to the s-BUSY block (starting at line 84) and add the following after the line that you just commented out:
This code adds the Diversion header to read tel:extension. Note that the tel:ext block is surrounded by greater and less than signed (triangle brackets if you will) which have a habit of not being displayed on web pages.
Also note that you need to use the names of your trunk (or 2 trunks if using Exchange 2013) connecting to Exchange. The Dial() command tells Asterisk to dial both trunks at the same time and direct the call to whichever answers first. Therefore if Exchange is listening on 5065 or 5067 the connection will work. I used ToExchangeUM5065 and ToExchangeUM5067 in my lab. Then I replace xxxx with ToExchangeUM5065 and yyyy with ToExchangeUM5067.
The s-NOMESSAGE block (at line 92) needs the following added after the line that has been commented out:
Again, change xxxx and yyyy for your two different trunk names that you create in the next part of this blog and make sure that the Diversion:<tel:ext> header includes triangle brackets around tel:ext.
Next you need to do the same for the s-DIRECTDIAL block:
As you can see, the three blocks of inserted code are all the same apart from the s-WORD value at the start of each.
One block of code is missing through from the FreePBX defaults. If you call an extension and it is busy Asterisk runs the code starting s-BUSY, but if the call is ignored then Asterisk attempts to find and run code starting s-NOANSWER and as this is missing it will route ignored calls to Asterisk voicemail. To route ignored calls to Exchange Server add the following block of text:
This new block is again a copy of s-BUSY (or the other two) and just the s-WORD bit changed to s-NOANSWER. For completion the Noop line (line 1 above) is also changed to NOANSWER so that the correct text is written to the Asterisk console and log files.
No other changes are needed in extensions_override_freepbx.conf. So save the file and restart Asterisk by using amportal restart from the console.
This is all that is needed to get Asterisk to talk to Exchange. For creating the Exchange dial plan I would recommend reading Brian's blog on creating and Exchange UM Lab. He goes into great detail in explaining everything. Here is the link to the blog:
http://blog.c7solutions.com/2012/07/building-exchange-unified-messaging-lab.html
After learning so much from this site, I thought I'd give a little back. I've scoured the interwebs, looking for tutorials that would allow me to hookup asterisk to Exchange UM. I had it running fairly reliably on my PiaF purple install, but that crashed and burned. So, I decided to setup Exchange 2013 and PiaF Green. This is what I needed to do get it to work. Credit goes to all authors of the various blogs and forum posts. This is NOT for the faint of heart. One needs the ability to figure out gremlins, and such when setting this up. These instructions worked for me, and they could, very well, work for you. I will try to look at the thread once a day to answer questions, however, I do have to make a living, so please be patient with me in responding.
First off, you need to tell Asterisk to use TCP in addition to UDP for SIP communication. Micro$oft, in their infinite wisdom, decided to only allow TCP SIP communication on all of their Unified Communications applications, which includes Exchange. To do this, you need to add 2 fields to the "Other SIP Settings" area of the "Asterisk SIP Settings" Menu.
After adding the 2 fields, enter the following settings to enable TCP communication:
Code:
tcpenable=yes
tcpbindaddr=0.0.0.0
Once that is completed, the next step is to configure a Trunk that will be used to communicate between Exchange and PiaF (For Exchange 2013, you need to create 2 Trunks one that uses Port 5065, and one that uses Port 5067)
Code:
General Settings
Trunk Name: ToExchange
Outgoing Settings
Trunk Name:ToExchange
PEER Details:
host=xxx.xxx.xxx.xxx (IP Address of Exchange Server)
type=friend
insecure=very
transport=tcp
port=5065 (For Exchange 2013 create a 2nd Trunk with Port 5067)
context=from-internal
qualify=yes
Now, we need to create an outbound route so that we can allow internal communication between Asterisk And Exchange. This is what needs to be added to the Outbound Route. For your trunk sequence, only add the newly created trunk that we just made. (For Exchange 2013, you would also add the 2nd trunk.)
Code:
Route Settings
Route Name: ToExchangeVM
Route Type: Intra-Company CHECKED
Music On Hold Default
Time Group: Permanent Route
Route Position: No Change
Additional Settings
Dial Patterns that will use this Route?
401
402
999
Trunk Sequence for Matched Routes?
0 Exchange Trunk
1 2nd Exchange Trunk, if using Exchange 2013
2
My Dial Patterns might look weird, but it's normal for this route. You need to enter every IVR, that you've configured in Exchange as a separate dial pattern. You also need to create a Misc Destination for EVERY Exchange hosted IVR as well as the "pilot identifier" to access voicemail. The default is 999. In my example I use 999 to access voicemail, 401 to access my first IVR, and 402 to access my second IVR.
Configure Asterisk to Forward Calls to Exchange Unified Messaging for Voicemail
Asterisk defaults to forwarding calls to its own voicemail extensions and so edits need to be made to the extensions.conf ( or linked files if using FreePBX) to route calls to the Exchange Server for voicemail.
Since we are using FreePBX, we need to edit /etc/asterisk/extensions_override_freepbx.conf.
The next section is copied from a blog post from Brian Reid, of C7 Solutions.
The first change is to copy the [macro-vm] section from /etc/asterisk/extensions_additional.conf into /etc/asterisk/extensions_override_freepbx.conf. [macro-vm] is approx 150 lines long and ends with “;--== end of [macro-vm] ==--;”.
Then we need to make some changes and additions to the macro-vm section. The first set of changes will comment out the code the directs calls to Asterisk voicemail and the additional lines will dial the Exchange Server trunks and add SIP Diversion headers so that Exchange knows which mailbox to answer the call for.
So first, locate the following lines and comment them out. The numbers in brackets at the start are the approx. location in extensions_override_freepbx.conf where you will find the line:
Code:
(86) exten => s-BUSY,n,VoiceMail(${MEXTEN}@${VMCONTEXT},${VM_OPTS}b${VMGAIN})
(92) exten => s-NOMESSAGE,n,VoiceMail(${MEXTEN}@${VMCONTEXT},s${VM_OPTS}${VMGAIN})
(97) exten => s-DIRECTDIAL,n,VoiceMail(${MEXTEN}@${VMCONTEXT},${VM_OPTS}${VM_DDTYPE}${VMGAIN})
Each of the above lines can be commented out by placing a semi-colon ( at the start of the line.
Return to the s-BUSY block (starting at line 84) and add the following after the line that you just commented out:
Code:
exten => s-BUSY,n,SIPAddHeader(Diversion:<tel:${MEXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
exten => s-BUSY,n,Dial(SIP/xxxx&SIP/yyyy) /* xxxx/yyyy here are the two trunk names, one for each TCP listening port */
exten => s-BUSY,n,Hangup
This code adds the Diversion header to read tel:extension. Note that the tel:ext block is surrounded by greater and less than signed (triangle brackets if you will) which have a habit of not being displayed on web pages.
Also note that you need to use the names of your trunk (or 2 trunks if using Exchange 2013) connecting to Exchange. The Dial() command tells Asterisk to dial both trunks at the same time and direct the call to whichever answers first. Therefore if Exchange is listening on 5065 or 5067 the connection will work. I used ToExchangeUM5065 and ToExchangeUM5067 in my lab. Then I replace xxxx with ToExchangeUM5065 and yyyy with ToExchangeUM5067.
The s-NOMESSAGE block (at line 92) needs the following added after the line that has been commented out:
Code:
exten => s-NOMESSAGE,n,SIPAddHeader(Diversion:<tel:${MEXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
exten => s-NOMESSAGE,n,Dial(SIP/xxxx&SIP/yyyy) /* xxxx/yyyy here are the two trunk names, one for each TCP listening port */
exten => s-NOMESSAGE,n,Hangup
Again, change xxxx and yyyy for your two different trunk names that you create in the next part of this blog and make sure that the Diversion:<tel:ext> header includes triangle brackets around tel:ext.
Next you need to do the same for the s-DIRECTDIAL block:
Code:
exten => s-DIRECTDIAL,n,SIPAddHeader(Diversion:<tel:${MEXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
exten => s-DIRECTDIAL,n,Dial(SIP/xxxx&SIP/yyyy) /* xxxx/yyyy here are the two trunk names, one for each TCP listening port */
exten => s-DIRECTDIAL,n,Hangup
As you can see, the three blocks of inserted code are all the same apart from the s-WORD value at the start of each.
One block of code is missing through from the FreePBX defaults. If you call an extension and it is busy Asterisk runs the code starting s-BUSY, but if the call is ignored then Asterisk attempts to find and run code starting s-NOANSWER and as this is missing it will route ignored calls to Asterisk voicemail. To route ignored calls to Exchange Server add the following block of text:
Code:
exten => s-NOANSWER,1,Noop(NOANSWER voicemail - Exchange UM)
exten => s-NOANSWER,n,Macro(get-vmcontext,${MEXTEN})
exten => s-NOANSWER,n,SIPAddHeader(Diversion:<tel:${MEXTEN}>\;reason=no-answer\;screen=no\;privacy=off)
exten => s-NOANSWER,n,Dial(SIP/xxxx&SIP/yyyy) /* xxxx/yyyy here are the two trunk names, one for each TCP listening port */
exten => s-NOANSWER,n,Hangup
exten => s-NOANSWER,n,Goto(exit-${VMSTATUS},1)
This new block is again a copy of s-BUSY (or the other two) and just the s-WORD bit changed to s-NOANSWER. For completion the Noop line (line 1 above) is also changed to NOANSWER so that the correct text is written to the Asterisk console and log files.
No other changes are needed in extensions_override_freepbx.conf. So save the file and restart Asterisk by using amportal restart from the console.
This is all that is needed to get Asterisk to talk to Exchange. For creating the Exchange dial plan I would recommend reading Brian's blog on creating and Exchange UM Lab. He goes into great detail in explaining everything. Here is the link to the blog:
http://blog.c7solutions.com/2012/07/building-exchange-unified-messaging-lab.html