Howwise RSS
VoIP & Phone Systems7 min read

FreePBX: Dial Voicemail Directly From a DID or Code

Short answer

To make FreePBX dial voicemail directly from a DID, point the inbound route at a Voicemail destination to let callers leave a message, or at a Custom Destination calling app-dialvm (*98) so staff can check messages.

Key takeaways
  • Leaving a message uses the Voicemail destination (the Voicemail() app); checking messages uses VoiceMailMain(), which needs a Custom Destination or Misc Application.
  • *97 runs VoiceMailMain(${AMPUSER}@default) and never asks for a mailbox, while *98 runs VoiceMailMain(@default) and asks for mailbox and PIN.
  • A DID that reaches VoiceMailMain with the s option skips the PIN, so anyone who dials it can read the mailbox.
  • The FreePBX voicemail context is default, so extension 1001 is mailbox 1001@default; a wrong context gives 'mailbox not found'.
  • Test by dialing the DID, watching asterisk -rvvv, and confirming with voicemail show users and dialplan show.

Leaving a message or checking messages: which do you need?

These are two different jobs handled by two different Asterisk applications. Mixing them up is the most common reason a setup "does nothing" or asks for the wrong thing.

Leaving a message uses Voicemail(), which plays a greeting and records. Checking messages uses VoiceMailMain(), which is the menu where you listen, delete and change greetings.

To freepbx dial voicemail directly from a DID, decide first which one the number is for. The rest of the setup follows from that choice.

GoalWho dialsAsterisk appFreePBX destination
Leave a message in 1001's mailboxOutside callersVoicemail(1001@default,u)Inbound route > Voicemail > 1001
Check own messages, no mailbox promptStaff from their own phoneVoiceMailMain(${AMPUSER}@default)Feature code *97
Check any mailbox, promptedStaff, remote or internalVoiceMailMain(@default)*98 / app-dialvm
Check a fixed mailbox from a DIDRemote staffVoiceMailMain(1001@default)Custom destination

How do I make FreePBX dial voicemail directly from a DID?

This is the leave-a-message case and needs no custom code. The route plays the greeting for that mailbox and records, without ringing any phone first.

The mailbox must be enabled on the extension's Voicemail tab, otherwise the destination exists but fails at runtime.

  1. Go to Connectivity > Inbound Routes and edit or add the route for the DID.
  2. Under Set Destination choose Voicemail, then pick the extension (for example 1001).
  3. Choose the message type: Default greeting uses the standard flow, Busy (vmb) plays the busy greeting, Unavailable (vmu) plays the unavailable greeting, and No Message (vms) plays no greeting, only a beep.
  4. Submit and click Apply Config. Skipping Apply Config is the usual reason a change has no effect.
  5. Check the generated destination, which looks like ext-local,vmu1001,1, with the commands below.
asterisk -rx "dialplan show ext-local" | grep -E "vm(b|u|s)1001"
asterisk -rx "voicemail show users" | grep 1001
Tip: Use vmu for a company mailbox nobody answers. Its unavailable greeting reads naturally, while the busy greeting suggests someone is on the phone.

What is the difference between *97 and *98 in FreePBX?

Both codes open the VoiceMailMain menu. They differ in how the mailbox is chosen, and that decides which one suits an outside caller.

*97 (My Voicemail) takes the mailbox from the calling extension, so it only makes sense from a registered phone. *98 (Dial Voicemail) asks for a mailbox number, then a PIN, so it works from any phone or trunk.

Item*97 My Voicemail*98 Dial Voicemail
DialplanVoiceMailMain(${AMPUSER}@default)VoiceMailMain(@default)
Mailbox sourceCaller's own extensionTyped by the caller
Prompts for mailbox numberNoYes
Prompts for PINYes, unless the mailbox is set to skip itYes
Context in dialplanapp-vmmainapp-dialvm
Fits an outside DIDPoorly, outside callers have no extensionYes
Tip: From an outside DID, ${AMPUSER} is empty or is the external number, so a *97 style destination prompts for a mailbox anyway or fails. That is why *98 is the right fit.

How do I check messages by calling an outside number?

Create a Custom Destination that points at the *98 context, then select it on an inbound route. Callers hear the mailbox and PIN prompts, so no extension is involved.

Open Admin > Custom Destinations and add a new entry. Use the Target below, give it a description such as Remote Voicemail, and tick Return only if you want the call to come back to a previous menu.

  1. Go to Admin > Custom Destinations > Add.
  2. Set Target to app-dialvm,s,1 and Description to Remote Voicemail.
  3. Submit and Apply Config.
  4. Open the inbound route for the chosen DID and set Destination to Custom Destinations > Remote Voicemail.
  5. Apply Config again, then test from a mobile phone.
Target:       app-dialvm,s,1
Description:  Remote Voicemail
Warning: A public number that reaches VoiceMailMain lets anyone guess mailbox numbers and PINs. Default or short PINs such as 1234 or the extension number are the main route to compromise, and a hijacked mailbox can be used for social engineering or call-forwarding fraud.

How do I build a custom voicemail context, and how do I lock it down?

For a fixed mailbox or extra control, write your own context in /etc/asterisk/extensions_custom.conf. The mailbox format is number@context, and FreePBX uses default, so 1001 is 1001@default. In multi-tenant or custom setups, match whatever context appears in voicemail show users.

The second form below allows entry only from known caller IDs, then still asks for the PIN. The s option on VoiceMailMain skips the password check, so use it only on a restricted, unpublished path.

[custom-vm-direct]
; Prompts for mailbox and PIN
exten => s,1,Answer()
 same => n,Wait(1)
 same => n,VoiceMailMain(@default)
 same => n,Hangup()

[custom-vm-fixed-nopin]
; DANGEROUS: no PIN. Only for a private, trusted path
exten => s,1,Answer()
 same => n,VoiceMailMain(1001@default,s)
 same => n,Hangup()

[custom-vm-restricted]
; Allowlist by CallerID, then still require the PIN
exten => s,1,NoOp(VM from ${CALLERID(num)})
 same => n,GotoIf($["${CALLERID(num)}" = "15551230001"]?ok)
 same => n,GotoIf($["${CALLERID(num)}" = "15551230002"]?ok)
 same => n,Playback(ss-noservice)
 same => n,Hangup()
 same => n(ok),VoiceMailMain(1001@default)
 same => n,Hangup()
Warning: CallerID can be spoofed, so an allowlist is a filter and not authentication. Always keep a strong PIN (6 or more digits, not the extension), use a DID that is not published, and run fail2ban on the PBX. Reload with dialplan reload, then create a Custom Destination with Target custom-vm-restricted,s,1.

How do I test it and what usually goes wrong?

Test from an internal phone first, then from outside through the DID. Keep a console open to see the dialplan execute and confirm that DTMF digits arrive.

SymptomLikely causeFix
Mailbox not found / invalidWrong context, or mailbox missingCheck voicemail show users, use 1001@default
Route does nothing after changeApply Config not clickedApply Config, then dialplan reload
Menu plays but digits are ignoredDTMF mismatch on the trunkSet DTMF to rfc4733 (or inband/auto) matching the provider
Silent greeting, just a beepNo greeting recordedRecord via *97 from the extension, or the Voicemail tab
Destination rejected or no mailboxVoicemail not enabled on the extensionEnable it on the extension's Voicemail tab
One-way or no audioNAT or RTP issueSet external media/signaling address and local_net, check RTP 10000-20000/UDP
  1. Dial *98 from an internal phone and confirm the mailbox prompt, then the PIN prompt.
  2. Run asterisk -rvvv and dial the DID from a mobile; look for Executing lines for app-dialvm or your custom context.
  3. Run pjsip set logger on and confirm digits arrive as RFC 4733 events or in-band tones.
  4. Enter a wrong PIN deliberately to confirm it is rejected, then the right one.
  5. Run voicemail show users to confirm the mailbox exists and message counts match.
asterisk -rvvv
dialplan show custom-vm-direct
dialplan show app-dialvm
voicemail show users
pjsip set logger on
rtp set debug on

What are the alternatives to a dedicated voicemail DID?

An IVR option such as "press 8 for voicemail" pointing at the same Custom Destination keeps the public DID unchanged and adds an extra step before the menu. Combine it with a time condition if you want it only reachable out of hours.

Voicemail email delivery with the recording attached (the Email Attachment setting on the extension's Voicemail tab) removes most need to dial in. A Directory can also route callers to a person's mailbox by name.

Staff who work remotely can also register a softphone to their extension and press *97, which avoids exposing any public retrieval number.

Common questions

Can I use *97 from an outside DID?

Not reliably. *97 assumes the caller is an extension and uses ${AMPUSER} as the mailbox, which an outside caller does not have. Use *98 or a custom context with a fixed mailbox instead.

How do I skip the PIN when checking voicemail?

Use VoiceMailMain(1001@default,s), which skips the password check. Only do this on an internal, non-published path, because anyone reaching it can read and delete messages.

Why does the voicemail destination say the mailbox is not available?

The mailbox is usually disabled, missing from the context, or the extension number does not match. Check voicemail show users and the Voicemail tab of the extension, then apply config.

What do the vmb, vmu and vms options mean?

They select the greeting: vmb plays the busy message, vmu plays the unavailable message, and vms skips the greeting and goes straight to the beep. They are the same variants FreePBX uses when a call is not answered.

Do I need fail2ban for this?

If a retrieval DID is reachable from the internet, yes. Repeated wrong PIN attempts are logged by Asterisk, and fail2ban can block abusive source IPs, though it does not replace strong PINs.

Related topics:freepbxvoicemailasteriskinbound routesdialplan