FreePBX | Register | Issues | Wiki | Portal | Support

Multiple custom extensions for sending emails when called

Tags: #<Tag:0x00007f74a2f45e70>


I’ve configured a custom extension that sends me an email if I’ve got a missed call. When the extension gets called, it sends an email to me and then hanging up using this script:

exten => s,1,NoOp(Entering user defined context  [send-email] in extensions_custom.conf)
exten => s,n,System(echo 'Call from ${CALLERID(name)} at  ${CALLERID(number)}' | mail -s 'SUBJECT' '')
exten => s,n,hangup()

The dial field of the custom extension is set to

I’ve got this from lgaetz.
I’d like to know how I can accomplish this for a second extension, I don’t really know how this stuff works, but I’m willing to learn.
If configuring the same thing and changing the “s” to “t” so the two codes can be differentiated, but then it doesn’t send anything at all.

(Lorne Gaetz) #2

Change the dialplan to:

exten => _.,1,NoOp(Entering user defined context  [send-email] in extensions_custom.conf)
exten => _.,n,set(emailaddresss=${STRREPLACE(EXTEN,:,@)})
exten => _.,n,System(echo 'Call from ${CALLERID(name)} at  ${CALLERID(number)}' | mail -s 'SUBJECT' '${emailaddresss}')
exten => _.,n,hangup()

Then the custom dial string becomes:


you replace the @ symbol in the email address with a :

(Itzik) #3

Curious. How does this get called?

(Lorne Gaetz) #4

You can’t remember posts from 4 years ago?

(Itzik) #5

Lol, you rock man.

(Itzik) #6

I was actually working recently on a similar project. Is there a possibility to pull the email address set in the Voicemail tab or in user management and set as a variable?

(Jared Busch) #7

You could certainly do it with a custom bit of SQL. I have no idea if those values are exposed any other way, but I doubt it.

I have a custom MySQL database at one site with a lot of data in it that is pulled in for outbound call checks. So for something like this, you should just need to add a call to the asterisk database to pull the info.


You can grep it out of the conf file

 grep ^${EXTEN}/etc/asterisk/voicemail.conf|cut -d ',' -f 3


I’ve modified the code slightly

exten => _.,1,NoOp(Entering user defined context [send-email-privat] in extensions_custom.conf)
exten => _.,n,System(echo ‘Anrufer “${CALLERID(name)}” mit der Telefonnummer “${CALLERID(number)}” bittet um Rückruf. (Anschluss 12345)’ | mail -s ‘Ein Rückruf wurde angefordert’ ‘’)
exten => _.,n,hangup()

Dialpattern is


But now it always send the same email twice. Any idea why?

(Tom Ray) #12

That will only work if the extension has voicemail enabled on it.


Damn, your right!! Never thought about that (looking for the correct emoticon here . . .)


Here are some recommendations: :sweat_smile::thinking::open_mouth:

(system) closed #15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.