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.

ApplicationTypical userPurpose
VoiceMailCallerPlay a greeting and deposit a new recording in a mailbox.
VoiceMailMainMailbox ownerAccess 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

ElementExamplePurpose
Mailbox target444Selects mailbox 444.
ContextdefaultSelects the voicemail context containing the mailbox.
u option,uUses the mailbox's unavailable greeting.
Complete application callVoiceMail(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@default to identify where the recording should go.
  • voicemail.conf must define mailbox 444 under the default context.
  • 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 AreaPrimary ResponsibilityRelevant Example Content
extensions.confDefines call routing and which dialplan applications execute.NoOp, Dial, and VoiceMail steps for extension 444.
voicemail.confDefines 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:

  1. The caller reaches extension 444.
  2. Dial(SIP/bob,12) attempts to ring the endpoint named bob for up to 12 seconds.
  3. If the endpoint does not answer and the call returns to the dialplan, execution continues to the next priority.
  4. 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 ComponentExample ValueMeaning
Voicemail base directory/var/spool/asterisk/voicemailTop-level directory for stored voicemail.
ContextdefaultVoicemail context containing the mailbox.
Mailbox444Mailbox receiving the message.
FolderINBOXDefault folder for newly deposited messages.
Complete path for 444@default/var/spool/asterisk/voicemail/default/444/INBOXMailbox 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 PatternFile TypePurpose
msgNNNN.txtMetadata textStores message information such as caller and timing details.
msgNNNN.wavAudio recordingContains the message in a WAV-compatible format.
msgNNNN.WAVAudio recordingAnother 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 Dial step is followed by a VoiceMail step in the same call flow.
  • Confirm that the incoming or internal route really reaches extension 444.
  • Check that SIP/bob is 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 default voicemail context.
  • Compare the dialplan target 444@default with the context and mailbox definition in voicemail.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 u option 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@context value.
  • Inspect the mailbox's INBOX directory 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@context identifies a mailbox within a voicemail context.
  • The u option selects the unavailable greeting.
  • Call-routing steps belong in the dialplan, such as extensions.conf; mailbox definitions belong in voicemail.conf.
  • For 444@default, the default INBOX path is /var/spool/asterisk/voicemail/default/444/INBOX.
  • A no-answer design normally places VoiceMail after the Dial attempt 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.

Review the Asterisk VoiceMail application lesson