I get an email when I receive SMS in chan dongle. I want to add subject that email.

I use PBX in Flash, Asterisk version 13.22.

  • Number 1 - I get email.
  • Number 2 - I don't get any mail.

    (1) exten => sms,n,System(sendmail -f from@gmail.com -t to@gmail.com < /var/log/asterisk/sms.txt) 
    (2) exten => sms,n,System(echo "Subject: Old and New full SMS File from ${DONGLENAME}"; /usr/sbin/sendmail -f from@gmail.com -t to@gmail.com < /var/log/asterisk/sms.txt)

Asterisk executes ONE command. Actually the best way is to write a Bash script with all Bash logic and send only params to it. Sure you can use Bash magic like you have in the other answer, but you have two problems here:

  • asterisk System call should be without special (for Asterisk) symbols and line have be quoted
  • it will be hard to remember after few month what that magic does

You also have a security risk here, for example if SMS has some special Bash symbols like '`', always be careful with it.


Try this approach:

exten => sms,n,System(( echo "Subject: Old and New full SMS File from ${DONGLENAME}"; echo; cat /var/log/asterisk/sms.txt ) | sendmail -f from@gmail.com -t to@gmail.com)
  • I have no clue why this is not working. I get email from bash put this line. But not receive from asterisk. – Khandaker Shahriar Amin Aug 20 '18 at 17:27

Try this, It should work:

exten => sms,n,System((echo "Subject: Old and New full SMS File from ${DONGLENAME}" && cat /var/log/asterisk/sms.txt) | /usr/sbin/sendmail -f from@gmail.com -t to@gmail.com)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.