Email not sent in script/AGI


Hi everybody,

Hope you can help me out with an issue I have. I am trying to send an email whenever the caller is answered with the voicemail. The issue is that the email is not sent from the script but when I run the same command outside of the script to send the email the email is sent.

So in /etc/asterisk/extensions.conf I have these four lines

exten => 200,1,Log(NOTICE, intern {DEVICE_STATE(SIP/{sip}-{CALLERID(NUM)})} from {sip}-{CALLERID(NUM)} to {sip}-${MACRO_EXTEN});
same => n,Set(;
same => n,AGI(;
same => n,Dial(SIP/200);

In line 3 I execute the script that should send out the email. Here the 6 lines of the script:
#$1 email address
#$2 from-cid
#$3 to-cid
echo -e "test email” | mailx -A gmail -s “TestScript”
exit 0

Although Asterisk is executing the script (I have put log commands in the script to verify) the email is not sent. When I execute the same script through the command line (sh, the email is sent and received. So only when asterisk runs the script it does not send the email.

I am running Asterisk v11.25.3 on DietPi on a armv7l running Linux.

Any help would be really appreciated.



Did you verify all permisions, also the path where the you have the script and also any path inside the script


Thanks for your reply. The script has all rights assigned, see below.

root@DietPi:/var/lib/asterisk/agi-bin# ls -l
total 24
-rw------- 1 root root 705 Nov 24 10:10 dead.letter
-rwxrwxrwx 1 root root 103 Nov 24 21:35
-rwxrwxrwx 1 root root 609 Nov 24 08:52
-rwxrwxrwx 1 root root 64 Aug 26 07:12
-rwxrwxrwx 1 root root 483 Nov 26 2017
-rwxrwxrwx 1 root root 1260 Nov 26 2017

Also in the Asterisk console I see that the script is executed.

== Using SIP RTP CoS mark 5

> 0x766167b8 – Strict RTP learning after remote address set to:

– Executing [201@extcos:1] Log (" SIP/200-00000003 ", " NOTICE, intern INVALID from -200 to - ") in new stack

[Nov 24 21:39:56] NOTICE [3436][C-00000004]: Ext. 201 : 1 @ extcos : intern INVALID from -200 to -

– Executing [201@extcos:2] AGI (" SIP/200-00000003 ", " ") in new stack

– Launched AGI Script /var/lib/asterisk/agi-bin/

– <SIP/200-00000003>AGI Script completed, returning 0

– Executing [201@extcos:3] Dial (" SIP/200-00000003 ", " SIP/201 ") in new stack

[Nov 24 21:39:56] WARNING [3436][C-00000004]: app_dial.c : 2455 dial_exec_full : Unable to create channel of type ‘SIP’ (cause 20 - Subscriber absent)

== Everyone is busy/congested at this time (1:0/0/1)

– Auto fallthrough, channel ‘SIP/200-00000003’ status is ‘CHANUNAVAIL’

The script contains just one line atm for testing purpose:
echo -e “testing email” | mailx -A gmail -s “TestScript”

If I just execute that script from command line (sh the email is sent out.


The script appears to have run, so I assume the problem is that you haven’t provided the full pathnames of the commands it uses, and the PATH environment variable isn’t suitable.

However, setting rwx for everyone, on executables is not a good idea, and some programs will actually check for this and refuse to run them.


Thanks David. I have changed the file permission to chmod 755 but still no luck.

What pathnames do you refer to? The agi-bin folder is specified in conf file /etc/asterisk/asterisk.conf as /var/lib/asterisk/agi-bin. Also what do you mean with PATH environment variable isn’t suitable?

Appreciate your help!


Those to echo and mailx


I managed to get it working through the mutt email client. Not sure why mailx is causing issues but at least I can send emails from the AGI script through mutt.

Thanks for the help everybody!