VMware ESXi and vSphere Cluster Management
Asterisk VoiceMail Application: Routing Calls to Mailboxes
Learn how Asterisk VoiceMail routes callers to mailboxes, selects unavailable greetings, handles no-answer calls, and stores recordings on disk.
What the VoiceMail application does
VoiceMail is an Asterisk dialplan application that plays a mailbox greeting and records the caller's message into that mailbox. It is used when a caller needs to leave a message, either because an extension routes directly to voicemail or because a call is unanswered.
VoiceMailMain has a different purpose. It is the application a mailbox owner uses to log in, listen to existing messages, and manage them.
| Application | Typical user | Purpose |
|---|---|---|
| VoiceMail | Caller | Play a greeting and deposit a new recording in a mailbox. |
| VoiceMailMain | Mailbox owner | Access and manage messages already stored in a mailbox. |
VoiceMail syntax and mailbox addressing
The general form is:
VoiceMail(mailbox[@context][&mailbox[@context]...][,options])
A mailbox is the destination for the recording. It may be a number or another configured mailbox identifier. A context is a named group of voicemail mailboxes. Together, they are written as mailbox@context, such as 444@default.
The mailbox must exist in the relevant voicemail configuration context. If the dialplan selects 444@default, Asterisk must be able to find mailbox 444 in the default voicemail context.
Some dialplan designs send one recording to more than one mailbox. Multiple targets can be specified with ampersands, for example:
VoiceMail(444@default&445@default,u)
Use multiple targets only when that behavior is intended, because each selected mailbox can receive the deposited message.
VoiceMail arguments and options
| Element | Example | Purpose |
|---|---|---|
| Mailbox target | 444 | Selects mailbox 444. |
| Context | default | Selects the voicemail context containing the mailbox. |
u option | ,u | Uses the mailbox's unavailable greeting. |
| Complete application call | VoiceMail(444@default,u) | Plays the unavailable greeting for mailbox 444 and then records the caller's message. |
With the u option, the expected caller flow is: Asterisk presents the mailbox's unavailable greeting, then gives the caller an opportunity to record a message.
Mailbox contexts and configuration
A voicemail context separates one group of mailboxes from another. This is useful when different departments, tenants, or numbering plans need independent mailbox namespaces or settings.
For the central example, the target is mailbox 444 in the default voicemail context: 444@default. The context and mailbox number affect both routing and storage:
- The dialplan uses
444@defaultto identify where the recording should go. voicemail.confmust define mailbox 444 under thedefaultcontext.- The same values determine the mailbox's directory under the voicemail storage hierarchy.
A simplified voicemail configuration might contain a context and mailbox definition similar to this:
[default]
444 => mailbox-password,Mailbox 444
The exact mailbox fields and settings depend on the Asterisk version and deployment. The important requirement is that mailbox 444 is defined inside the default voicemail context.
Keep dialplan and voicemail configuration separate
| Configuration Area | Primary Responsibility | Relevant Example Content |
|---|---|---|
extensions.conf | Defines call routing and which dialplan applications execute. | NoOp, Dial, and VoiceMail steps for extension 444. |
voicemail.conf | Defines voicemail contexts, mailboxes, greetings, and voicemail-related settings. | The [default] context and mailbox 444. |
VoiceMail is invoked from the dialplan, normally in extensions.conf or another active dialplan source. It is not invoked by placing application lines in voicemail.conf. The voicemail file defines the destination; the dialplan decides when to send a call there.
Route an extension directly to voicemail
If every call to extension 444 should go directly to voicemail, place the routing in the active dialplan:
exten => 444,1,NoOp()
same => n,VoiceMail(444@default,u)
NoOp performs no call action. It is useful as a visible call-flow marker and can be expanded with a description when troubleshooting. The next priority invokes VoiceMail, selects mailbox 444 in context default, and requests the unavailable greeting with u.
Ring an endpoint before sending the call to voicemail
A common design rings an endpoint first and continues to voicemail only if the endpoint does not answer. This example rings SIP/bob for 12 seconds:
exten => 444,1,NoOp()
same => n,Dial(SIP/bob,12)
same => n,VoiceMail(444@default,u)
The call sequence is:
- The caller reaches extension 444.
Dial(SIP/bob,12)attempts to ring the endpoint namedbobfor up to 12 seconds.- If the endpoint does not answer and the call returns to the dialplan, execution continues to the next priority.
VoiceMail(444@default,u)plays the unavailable greeting and records the caller's message.
Where voicemail messages are stored
With the default filesystem storage layout, voicemail messages are under:
/var/spool/asterisk/voicemail
The generalized mailbox location is:
/var/spool/asterisk/voicemail/<context>/<mailbox>/INBOX
| Path Component | Example Value | Meaning |
|---|---|---|
| Voicemail base directory | /var/spool/asterisk/voicemail | Top-level directory for stored voicemail. |
| Context | default | Voicemail context containing the mailbox. |
| Mailbox | 444 | Mailbox receiving the message. |
| Folder | INBOX | Default folder for newly deposited messages. |
| Complete path for 444@default | /var/spool/asterisk/voicemail/default/444/INBOX | Mailbox 444's default incoming-message directory. |
Therefore, a message sent to 444@default is normally stored in:
/var/spool/asterisk/voicemail/default/444/INBOX
Each message can include a metadata text file and one or more audio files in formats enabled by the Asterisk installation.
Typical message files
| Filename Pattern | File Type | Purpose |
|---|---|---|
msgNNNN.txt | Metadata text | Stores message information such as caller and timing details. |
msgNNNN.wav | Audio recording | Contains the message in a WAV-compatible format. |
msgNNNN.WAV | Audio recording | Another possible audio filename or format variant, depending on configuration. |
The same message number links related files. For example, msg0000.txt is metadata for the recording represented by an audio file beginning with msg0000.
Inspect recorded messages from the command line
After recording a message for mailbox 444, list its INBOX directory with:
ls -l /var/spool/asterisk/voicemail/default/444/INBOX
Example output may include:
msg0000.txt
msg0000.wav
Use the exact mailbox and context from the dialplan when constructing the path. A message may also be in another mailbox folder if it has been moved or processed.
Filesystem permissions and ownership matter. The Asterisk service account must be able to create and access directories and recordings in the voicemail storage hierarchy. If recordings fail or files cannot be read, inspect ownership and permissions on the base directory, context directory, mailbox directory, and INBOX.
Troubleshooting checklist
The call does not reach voicemail after the endpoint fails to answer
- Verify that the
Dialstep is followed by aVoiceMailstep in the same call flow. - Confirm that the incoming or internal route really reaches extension 444.
- Check that
SIP/bobis the correct endpoint target and that the timeout is 12 seconds. - Review any Dial result handling that might transfer the call elsewhere instead of continuing to VoiceMail.
Asterisk cannot find mailbox 444
- Confirm that mailbox 444 is defined in the
defaultvoicemail context. - Compare the dialplan target
444@defaultwith the context and mailbox definition invoicemail.conf. - Check for spelling, numbering, or configuration reload errors.
Dialplan lines were placed in the wrong file
Move extension routing and application calls such as Dial and VoiceMail to extensions.conf or the active dialplan source. Keep mailbox definitions and voicemail settings in voicemail.conf.
The caller hears an unexpected greeting
- Verify that the
uoption is present when the unavailable greeting is required. - Confirm that the mailbox's unavailable greeting has been recorded or configured as expected.
- Check that the call is reaching the intended mailbox and context.
Recorded messages are not visible in the expected folder
- Reconstruct the path from the exact
mailbox@contextvalue. - Inspect the mailbox's
INBOXdirectory and other relevant voicemail folders. - Check filesystem ownership and permissions throughout the voicemail storage hierarchy.
Exam-relevant points
- VoiceMail deposits a caller's recording; VoiceMailMain lets a mailbox owner access stored messages.
- The format
mailbox@contextidentifies a mailbox within a voicemail context. - The
uoption selects the unavailable greeting. - Call-routing steps belong in the dialplan, such as
extensions.conf; mailbox definitions belong invoicemail.conf. - For
444@default, the default INBOX path is/var/spool/asterisk/voicemail/default/444/INBOX. - A no-answer design normally places
VoiceMailafter theDialattempt so execution can continue to the fallback.
Summary
Use VoiceMail in the dialplan when a caller should leave a message. Select the mailbox with a number or mailbox@context, use the u option for the unavailable greeting, and ensure the mailbox exists in the matching context in voicemail.conf. For extension 444, the target 444@default normally stores new messages under /var/spool/asterisk/voicemail/default/444/INBOX. Use VoiceMailMain separately when the mailbox owner needs to retrieve or manage those messages.