Mailcmd is being ignored

I have setup email on free-pbx 17 debian host. Email on voicemail is working as expected. Then I went to “Settings → Voicemail Admin → Settings → Email Config” and changed Mail Command to “/usr/sbin/sendmail-custom” which is a shell script:

#!/bin/sh

# Get absolute path to the script's directory
script_dir="$(cd "$(dirname "$0")" && pwd)"

# Generate timestamped filename
timestamp=$(date +"%Y%m%d_%H%M%S")
outfile="$script_dir/email_$timestamp.txt"

# Read email from stdin, save to file, and print
cat - | tee "$outfile"

The file has these permissions:

namei -l /usr/sbin/sendmail-custom 

drwxr-xr-x root     root     /
drwxr-xr-x root     root     usr
drwxr-xr-x root     root     sbin
-rwxr-xr-x asterisk asterisk sendmail-custom

For some reasons, my shell script is never called. I am expecting a file to be created in the current working directory. What am I missing here?

The script is trying to write to /usr/sbin/ which the asterisk user can’t write to. Change your output directory to somewhere writable:

#!/bin/sh
outfile="/tmp/email_$(date +"%Y%m%d_%H%M%S").txt"
cat - | tee "$outfile"

Also, FreePBX expects the mail command to actually send the email. Your script only saves it. Add the sendmail call:

#!/bin/sh
outfile="/tmp/email_$(date +"%Y%m%d_%H%M%S").txt"
cat - | tee "$outfile" | /usr/sbin/sendmail "$@"

Check /var/log/asterisk/full for any errors when voicemail tries to send. You can also add debug logging to confirm the script is being called:

echo "$(date): called with $@" >> /tmp/sendmail-debug.log
1 Like

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