Calling an extension to send email

Hi all,

I have a custom extension which if called needs to send an email to an address.

I’ve had this solution working for a while but it seems to have stopped working now…no emails are being sent, tried using a different address.

Definitely not a spam folder issues either.

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

Dial field on the custom extension under the advanced tab is: local/s@send-email

Checked the firewall, everything seems ok, freepbx is sending admin alert emails, and it also works if you manually enter the commands into the command prompt

echo ‘Call from ${CALLERID(name)} at ${CALLERID(number)}’ | mail -s ‘SUBJECT’ ‘[email protected]

Just wondering iff anyone could help me.

Thanks.

Asterisk Log

[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [state-not_set@sub-presencestate-display:1] Set("SIP/2000-00000011", "PRESENCESTATE_DISPLAY=") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [state-not_set@sub-presencestate-display:2] Return("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:47] Set("SIP/2000-00000011", "CONNECTEDLINE(name,i)=pager") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:48] Set("SIP/2000-00000011", "CONNECTEDLINE(num)=9005") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:49] Set("SIP/2000-00000011", "D_OPTIONS=TtrI") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:50] Macro("SIP/2000-00000011", "dialout-one-predial-hook,") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dialout-one-predial-hook:1] MacroExit("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:51] ExecIf("SIP/2000-00000011", "0?Set(D_OPTIONS=trII)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:52] NoOp("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:53] ExecIf("SIP/2000-00000011", "0?Set(D_OPTIONS=TtrIg)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:54] Dial("SIP/2000-00000011", "local/s@send-email,,TtrIb(func-apply-sipheaders^s^1)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_stack.c: Local/s@send-email-00000003;1 Internal Gosub(func-apply-sipheaders,s,1) start
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@func-apply-sipheaders:1] NoOp("Local/s@send-email-00000003;1", "Applying SIP Headers to channel Local/s@send-email-00000003;1") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@func-apply-sipheaders:2] Set("Local/s@send-email-00000003;1", "TECH=Local") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@func-apply-sipheaders:3] Set("Local/s@send-email-00000003;1", "SIPHEADERKEYS=") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@func-apply-sipheaders:4] While("Local/s@send-email-00000003;1", "0") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_while.c: Jumping to priority 12
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@func-apply-sipheaders:13] Return("Local/s@send-email-00000003;1", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_stack.c: Spawn extension (send-email, 9005, 1) exited non-zero on 'Local/s@send-email-00000003;1'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_stack.c: Local/s@send-email-00000003;1 Internal Gosub(func-apply-sipheaders,s,1) complete GOSUB_RETVAL=
[2019-09-30 07:32:32] VERBOSE[6895][C-0000000a] pbx.c: Executing [s@send-email:1] NoOp("Local/s@send-email-00000003;2", "Entering user defined context [send-email] in extensions_custom.conf") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_dial.c: Called local/s@send-email
[2019-09-30 07:32:32] VERBOSE[6895][C-0000000a] pbx.c: Executing [s@send-email:2] System("Local/s@send-email-00000003;2", "echo 'Call from davids Desk at 2000' | mail -s 'SUBJECT' '[email protected]'") in new stack
[2019-09-30 07:32:32] VERBOSE[6895][C-0000000a] pbx.c: Executing [s@send-email:3] System("Local/s@send-email-00000003;2", "echo 'Call from davids Desk at 2000' | mail -s 'SUBJECT' '[email protected]'") in new stack
[2019-09-30 07:32:32] VERBOSE[6895][C-0000000a] pbx.c: Executing [s@send-email:4] Hangup("Local/s@send-email-00000003;2", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6895][C-0000000a] pbx.c: Spawn extension (send-email, s, 4) exited non-zero on 'Local/s@send-email-00000003;2'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_dial.c: No one is available to answer at this time (1:0/0/0)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:55] ExecIf("SIP/2000-00000011", "0?MacroExit()") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:56] ExecIf("SIP/2000-00000011", "0?Set(DIALSTATUS=)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:57] GosubIf("SIP/2000-00000011", "0?s-NOANSWER,1()") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-dial-one:58] MacroExit("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:27] Set("SIP/2000-00000011", "SV_DIALSTATUS=NOANSWER") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:28] GosubIf("SIP/2000-00000011", "0?docfu,1()") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:29] GosubIf("SIP/2000-00000011", "0?docfb,1()") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:30] Set("SIP/2000-00000011", "DIALSTATUS=NOANSWER") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:31] ExecIf("SIP/2000-00000011", "0?MacroExit()") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-exten-vm:32] GotoIf("SIP/2000-00000011", "1?s-NOANSWER,1") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx_builtins.c: Goto (macro-exten-vm,s-NOANSWER,1)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s-NOANSWER@macro-exten-vm:1] GotoIf("SIP/2000-00000011", "0?exit,1") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s-NOANSWER@macro-exten-vm:2] PlayTones("SIP/2000-00000011", "congestion") in new stack
[2019-09-30 07:32:32] WARNING[6892][C-0000000a] translate.c: no samples for alawtolin
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s-NOANSWER@macro-exten-vm:3] Congestion("SIP/2000-00000011", "10") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_macro.c: Spawn extension (macro-exten-vm, s-NOANSWER, 3) exited non-zero on 'SIP/2000-00000011' in macro 'exten-vm'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Spawn extension (from-internal, 9005, 2) exited non-zero on 'SIP/2000-00000011'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [h@from-internal:1] Macro("SIP/2000-00000011", "hangupcall") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:1] GotoIf("SIP/2000-00000011", "1?theend") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx_builtins.c: Goto (macro-hangupcall,s,3)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:3] ExecIf("SIP/2000-00000011", "0?Set(CDR(recordingfile)=)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:4] NoOp("SIP/2000-00000011", " montior file= /var/spool/asterisk/monitor/2019/09/30/internal-9005-2000-20190930-073231-1569828751.23.wav") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:5] GotoIf("SIP/2000-00000011", "1?skipagi") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx_builtins.c: Goto (macro-hangupcall,s,7)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:7] Hangup("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_macro.c: Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'SIP/2000-00000011' in macro 'hangupcall'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [h@from-internal:1] Macro("SIP/2000-00000011", "hangupcall") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:1] GotoIf("SIP/2000-00000011", "1?theend") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx_builtins.c: Goto (macro-hangupcall,s,3)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:3] ExecIf("SIP/2000-00000011", "0?Set(CDR(recordingfile)=)") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:4] NoOp("SIP/2000-00000011", " montior file= /var/spool/asterisk/monitor/2019/09/30/internal-9005-2000-20190930-073231-1569828751.23.wav") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:5] GotoIf("SIP/2000-00000011", "1?skipagi") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx_builtins.c: Goto (macro-hangupcall,s,7)
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Executing [s@macro-hangupcall:7] Hangup("SIP/2000-00000011", "") in new stack
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] app_macro.c: Spawn extension (macro-hangupcall, s, 7) exited non-zero on 'SIP/2000-00000011' in macro 'hangupcall'
[2019-09-30 07:32:32] VERBOSE[6892][C-0000000a] pbx.c: Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/2000-00000011'
[2019-09-30 07:32:32] VERBOSE[6894][C-0000000a] app_mixmonitor.c: MixMonitor close filestream (mixed)
[2019-09-30 07:32:32] VERBOSE[6894][C-0000000a] app_mixmonitor.c: End MixMonitor Recording SIP/2000-00000011

Obvious problem 1 - you have two priority ‘1’ steps.

Probably not THE problem, but a problem.

It says your System call is failing. Are you sure the $PATH for Asterisk includes ‘mail’?

Not too sure, ahh do you know how I can check this?

Try using full pathnames to all of the programs. If that clears it, you’ll know. Short of that, I can’t think of an easy way to check the executable selection path in Asterisk.

the only mail I can find is a folder /var/mail/

And in that is 3 very strange text files with strange text in them that appear to be emails that i’ve never seen before.

Files are named

root
mail
asterisk

Those are the mail directories.

If your mail program isn’t available, that would cause the problem, but you said that when you execute the command from the command line it works, so I suspect you are looking in the wrong place.

The command you are looking for is find / -name ‘mail’ (with the single quotes). That should get you pretty close.

Thanks for that Dave,

Unfortunately that command you provided returned nothing at all.

And yes manually executing that command does send the email successfully.

Is it too late to mention that i’m using the raspberry pi version of asterisk?

Linux is Linux, so that doesn’t matter.

Try “which mail”.

You are doing this from the Command Prompt, right?

I tried installing postfix during this time, still no luck.

That command you sent me there returns

“/usr/bin/mail”, from the command prompt yes.

You need to check all this as the asterisk user. First as root

echo $PATH
which mail
.
.

Then as asterisk

su asterisk
echo $PATH
which mail
echo stuff|mail -s subject [email protected]
etc.

Try that.

root@raspbx:~# su asterisk
$
$ echo $PATH
which mail
echo stuff|mail -s subject [email protected]
etc./usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
$ /usr/bin/mail
$ $
sh: 5: etc.: not found
you have mail
$

root@raspbx:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@raspbx:~# which mail
/usr/bin/mail

Still no luck i’m afraid…

You should use double quotes for sh to expand your variables.

Normally, I’d agree totally, and in this case it wouldn’t hurt, but I doubt that it will make any difference. Asterisk is expanding the variables before the system() call is made, so he should be good.

On the mail sending front - check the file /var/log/maillog to see why the local mail program is failing.

Also - this question has almost nothing to do with Asterisk or FreePBX. You are troubleshooting a mail program problem, which is outside the scope of the group. We don’t mind helping, but your last answer:

Is the same as “Nope - guess again”. I usually stop helping at this point. If you aren’t going to do even the simplest troubleshooting, I’m not going to spend my time doing tech support for you for free.

1 Like

:wink: , normally I would agree but here the OP is using raspbx, so the mail server will be exim and the log file will likely not be /var/log/maillog, I am happy to be corrected though . . .

Thanks Blue, I agree, already using that, but the problem is that the email won’t send. I’m reinstalling raspbx from scratch now, see if that somehow counts towards “simplest troubleshooting”.

Hmmmmmm perhaps…
Too late now, memory card is being re-imaged.

I don’t think I could have though, last time I tried to install the system admin mod, I was having trouble getting it to work, maybe doesn’t work with an rpi. Not all modules work on the raspberry pi version.

But thanks for the help :slight_smile:

You can’t install commercial modules on RasPBX. You’re on your own for this.

Reinstall worked, working fine.

Tried restoring the backup, and that’s went it went back to square one and problems came back.

Had to rebuild my config from scratch, luckily there’s not too many phones on our system.

Thanks anyway for your help guys.