0

I'm trying to send an asterisk voice recording out via email using the script found here but instead of sending the file, it just puts the path to the file at the top of the email sent. I believe all the permissions are correct and the log files aren't showing any errors. I was hoping someone could help me troubleshoot this further.

The file name for the attachment appears to be correct when I run ls -lrt against the file at the top of the email. Is there any way to get postfix to add more verbosity to its logs?

The script

#!/bin/bash
#This script emails the recorded call right after the call is hung up. Below are    the variables passed through asterisk
# $1 - year
# $2 - month
# $3 - day
# $4 - Time String
# $5 - Source
# $6 - File
# $7 - Destination
# $dt - Date and Time


dt=$(date '+%m/%d/%Y %r');


echo -e "You have a new call recording to listen to \n\n
 The call date and time was $dt \n\n 
 The call was from $5 \n\n
 The call was to $7 \n\n

 Please see the attached file \n\n" | mail -a /var/spool/asterisk/monitor/$1/$2/$3/$6 -s "New Call Recording" email@domain.com

Which sends out the following email

Heading "New Call Recording"

/var/spool/asterisk/monitor/2016/02/11/internal-99-101-20160211-123644-1455154604.21.wav

You have a new call recording to listen to 


The call date and time was 02/11/2016 12:36:53 PM 


The call was from 101 


The call was to 99 



Please see the attached file 

ps - aux shows Asterisk is running as its own user

ps -aux | grep asterisk

asterisk   619  0.0  0.8 314092  8532 ?        S    12:26   0:00 /usr/sbin/apache2 -k start
asterisk   621  0.0  0.8 314092  8532 ?        S    12:26   0:00 /usr/sbin/apache2 -k start
asterisk   622  0.0  0.8 314092  8532 ?        S    12:26   0:00 /usr/sbin/apache2 -k start
asterisk   623  0.0  0.8 314092  8532 ?        S    12:26   0:00 /usr/sbin/apache2 -k start
asterisk   624  0.0  0.8 314092  8532 ?        S    12:26   0:00 /usr/sbin/apache2 -k start
asterisk   971  1.2  4.9 1855636 50188 ?       Ssl  12:26   0:15 /usr/sbin/asterisk -U asterisk -G asterisk

The mail.log file shows the user asterisk is the account which is sending the outbound mail.

/var/log# cat mail.log

Feb 11 12:36:07 APSPBX postfix/pickup[1172]: 9B54061A6B: uid=1001 from=<asterisk>
Feb 11 12:36:07 APSPBX postfix/cleanup[1701]: 9B54061A6B: message-id=<20160211013607.9B54061A6B@APSPBX>
Feb 11 12:36:07 APSPBX postfix/qmgr[1173]: 9B54061A6B: from=<asterisk@APSPBX>, size=619, nrcpt=1 (queue active)
Feb 11 12:36:22 APSPBX postfix/smtp[1644]: 9B54061A6B: to=<email@domain.com>, relay=smtp.gmail.com[173.194.72.108]:587, delay=15, delays=0.02/0/13/1.8, dsn=2.0.0, status=sent (250 2.0.0 OK 1455154590 s21sm7891538pfi.29 - gsmtp)
Feb 11 12:36:22 APSPBX postfix/qmgr[1173]: 9B54061A6B: removed

The folder and files which postfix is trying to get the attachment for are owned by the asterisk user.

ls -lrt /var/spool/asterisk/monitor/2016/02/11/

total 484
-rw-r--r-- 1 asterisk asterisk 139564 Feb 11 12:34 internal-99-101-20160211-123412-1455154452.7.wav
-rw-r--r-- 1 asterisk asterisk 213164 Feb 11 12:36 internal-99-101-20160211-123554-1455154554.14.wav
-rw-r--r-- 1 asterisk asterisk 135084 Feb 11 12:36 internal-99-101-20160211-123644-1455154604.21.wav

Thanks in advance

0

It seems you are using the GNU Mailutils where the -a option means appends a header (see below).

−a, −−append=HEADER: VALUE append given header to the message being sent

As for the mailx utility the -a option refers to an attachment:

-a file

Attach the given file to the message.

So check your OS and the distribution package you are using. With command like man mail, you can find out yourself, which mail command you are using and what the -a option means.

For an alternative solution, you can just use the mutt command:

echo "Here goes the message body....." | mutt -a "/path/to/attachment_file" -s "Subject.." -- recipient@example.com
| improve this answer | |
  • Thanks, it was an easy fix, the only change was adding the -- before the email address. – Duncan Murray Feb 12 '16 at 6:23

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.