[asterisk-users] Mailing a fax with mutt does not succeed
Larry Moore
lmoore at omninet.net.au
Fri Jun 21 21:44:54 CDT 2013
On 20/06/2013 2:03 AM, Daniel - Asterisk wrote:
> Hello everyone,
> I'm trying to send a received fax with mutt, when I try it from the
> Linux shel it works, but when trying with Asterisk's System command it
> doesn't.
> Successful Linux command:
> echo | mutt -s "New fax" earohuanca at gmail.com
> <mailto:earohuanca at gmail.com> -a /tmp/faxes/201306191111.tif
> Unsuccessful Asterisk Command:
> same => n,System(mutt -s "New fax" elder.arohuanca at gmail.com
> <mailto:elder.arohuanca at gmail.com> -a ${FAXDEST}/${tempfax}.tif)
> I'm using Asterisk 1.8.19.0 on Debian 6.0.6, Asterisk was installed by root.
> Any hint will be appreciated.
> Elder D. Arohuanca
> Lima - Peru
>
>
> --
Reading the responses to this thread I suspect the issue is that the
Muttrc file cannot be found, I am assuming the user:group Asterisk is
running as does not have a shell associated with it nor a home directory.
I am using OpenBSD and the above is true for my environment.
I have in my Asterisk Spool directory the folder structure
/var/spool/asterisk/fax/received. This folder is read-write for the
account Asterisk runs as.
On my system I set it up to use macros, one to receive the fax and
another to send the e-mail if one was received. The calling of the macro
to send the e-mail is performed in the Hangup extension.
I use extensions.ael on my system so here are the macros I set up;
macro fax-receive( fax-number, header-info, sender, recipient ) {
/*
${ARG1} is Receiving Station Fax Number
${ARG2} is Fax Header Information
${ARG3} is Fax Sender E-mail Address
${ARG4} is Fax Recipient E-mail Address
*/
NoOp(**** FAX RECEIVE ****);
Set(FAXOPT(localstationid)=${LOCAL(fax-number)});
Set(FAXOPT(headerinfo)=${LOCAL(header-info)});
Set(FROMADDR=${LOCAL(sender)});
Set(TOADDR=${LOCAL(recipient)});
NoOp(**** SETTING FAXOPT ****);
NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)});
NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)});
NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)});
Set(RXSTART=${EPOCH});
Set(FAXRXPATH=/var/spool/asterisk/fax/received);
Set(FAXRXFILE=fax-${CALLERID(number)}-${UNIQUEID});
NoOp(**** RECEIVING FAX : ${FAXRXFILE} ****);
ReceiveFAX(${FAXRXPATH}/${FAXRXFILE}.tif,fd);
NoOp(**** Subroutine Return ****);
return;
};
macro email_rxfax() {
Set(CALLDURATION=$[(${EPOCH}-${RXSTART})]);
System(FAXRXFILE=${FAXRXFILE} FAXRXPATH=${FAXRXPATH}
FAXRXSTATUS="${FAXOPT(status)}" FAXERROR="${FAXOPT(statusstr)}"
FROMADDR="${FROMADDR}" TOADDR="${TOADDR}"
LOCALSTATIONID="${FAXOPT(localstationid)}"
REMOTESTATIONID="${REMOTESTATIONID}" FAX
PAGES=${FAXOPT(pages)} FAXBITRATE=${FAXOPT(rate)}
FAXRESOLUTION=${FAXOPT(resolution)} CIDNUMBER="${CALLERID(number)}" CIDNAME
="${CALLERID(name)}" CALLDURATION=${CALLDURATION}
/usr/local/sbin/afax2email);
NoOp(**** STATUS : ${SYSTEMSTATUS} ****);
NoOp(**** Subroutine Return ****);
return;
};
Note, the System() line in email_rxfax() is one long line before the NoOp().
Here is an example entry in extensions.ael;
context fax-pstn1 {
fax => {
NoOp(Fax Received ${STRFTIME(,,%F %T %z)});
&fax-receive(+61 8 9XXXXXXX,Your Business
Name,FaxMaster@<your.domain.name>,lmoore@<your.domain.name>);
};
h => {
if ( "X${FAXRXFILE}" != "X" )
{
&email_rxfax();
}
NoOp(Call/Fax Ended ${STRFTIME(,,%F %T %z)});
};
};
Here is a sample extensions.ael entry for an incioming fax.
context fax-pstn1 {
fax => {
NoOp(Fax Received ${STRFTIME(,,%F %T %z)});
&fax-receive(+61 8 9XXXXXXX,Your Business
Name,FaxMaster@<your.domain.name>,lmoore@<your.domain.name>);
};
h => {
if ( "X${FAXRXFILE}" != "X" )
{
&email_rxfax();
}
NoOp(Call/Fax Ended ${STRFTIME(,,%F %T %z)});
};
};
I created a Muttrc file in /etc/asterisk, I use msmtp for the mail
progam, sendmail works but I didn't like the Envelope-From information
sendmail would add hence using msmtp, because the user asterisk runs as
does not have a home directory nor a shell I _had_ to use an RC file for
mutt. Here is my Muttrc file.
set sendmail="/usr/local/bin/msmtp"
set use_from=yes
set realname="Asterisk Fax Agent"
set from=FaxMaster
set record=""
#set envelope_from=yes
This is the afax2email script I use, note that mutt is called with "-F
/etc/asterisk/Muttrc".
#! /bin/ksh
#
# Script to e-mail a received fax from Asterisk
#
#
# Environment variables imported from Asterisk
#
EMAIL="Asterisk Fax Agent <$FROMADDR>"
export EMAIL SUBJECT TOADDR FROMADDR
TIFF2PDF="/usr/local/bin/tiff2pdf"
TIFFINFO="/usr/local/bin/tiffinfo"
MAILER="/usr/local/bin/mutt"
MAILERARGS="-F /etc/asterisk/Muttrc"
FILEPATH="$FAXRXPATH/$FAXRXFILE"
FAXIMAGE="$FILEPATH.tif"
PDFFILE="$FILEPATH.pdf"
MSGFILE="$FILEPATH.msg"
DURATION=`printf "%.2d" "$CALLDURATION"`
if [[ "$CALLDURATION" -ge "60" && "$CALLDURATION" -lt "3600" ]]; then
S=$CALLDURATION
((mins=S/60))
((secs=S%60))
DURATION=`printf "%.2d:%.2d\n" "$mins" "$secs"`
fi
if [ "$CALLDURATION" -ge "3600" ]; then
S=$CALLDURATION
((hours=S/3600))
((mins=S%3600/60))
((secs=S%60))
DURATION=`printf "%d:%.2d:%.2d\n" "$hours" "$mins" "$secs"`
fi
if [[ -d "${FAXRXPATH}" && -w "${FAXRXPATH}" ]]; then
if [ X"${FAXRXSTATUS}" = X"SUCCESS" ]; then
SUBJECT="Facsimile received from \"$REMOTESTATIONID\""
echo "A facsimile has been received on `printf "%s"
"$LOCALSTATIONID"`." > "$MSGFILE"
fi
if [ X"${FAXRXSTATUS}" = X"FAILED" ]; then
if [ "$FAXPAGES" -ne "0" ]; then
SUBJECT="Facsimile reception failed from
\"$REMOTESTATIONID\""
else
SUBJECT="Facsimile reception failed from
telephone number \"$CIDNUMBER\""
fi
echo "Problems encountered receiving facsimile on
`printf "%s" "$LOCALSTATIONID"`." > "$MSGFILE"
else
if [[ X"${FAXRXSTATUS}" != X"SUCCESS" &&
X"${FAXRXSTATUS}" != X"FAILED" ]]; then
SUBJECT="Facsimile reception failed from
telephone number \"$CIDNUMBER\""
echo "An unknown error was encountered
receiving a facsimile on `printf "%s" "$LOCALSTATIONID"`." > "
$MSGFILE"
fi
fi
echo >> "$MSGFILE"
printf "%18s" "Sender: " >> "$MSGFILE"; printf "%-20s\n"
"${REMOTESTATIONID}" >> "$MSGFILE"
printf "%18s" "Pages: " >> "$MSGFILE"; printf "%-20s\n"
"${FAXPAGES}" >> "$MSGFILE"
printf "%18s" "Signal Rate: " >> "$MSGFILE"; printf "%-20s\n"
"${FAXBITRATE} bit/s" >> "$MSGFILE"
printf "%18s" "CallerID Number: " >> "$MSGFILE"; printf
"%-20s\n" "${CIDNUMBER}" >> "$MSGFILE"
printf "%18s" "CallerID Name: " >> "$MSGFILE"; printf "%-20s\n"
"${CIDNAME}" >> "$MSGFILE"
printf "%18s" "Call Duration: " >> "$MSGFILE"; printf "%-20s\n"
"${DURATION}" >> "$MSGFILE"
printf "%18s" "Status: " >> "$MSGFILE"; printf "%-20s\n"
"${FAXERROR}" >> "$MSGFILE"
if [ -e "${FAXIMAGE}" ]; then
if (`$TIFF2PDF -o "$PDFFILE" "$FAXIMAGE"`) ; then
$MAILER $MAILERARGS -s "$SUBJECT" -a "$PDFFILE"
-- "$TOADDR" < "$MSGFILE"
else
$MAILER $MAILERARGS -s "$SUBJECT" -a
"$FAXIMAGE" -- "$TOADDR" < "$MSGFILE"
fi
rm -f "$PDFFILE" "$MSGFILE"
else
$MAILER $MAILERARGS -s "$SUBJECT" "$TOADDR" < "$MSGFILE"
rm -f "$MSGFILE"
fi
else
echo "Unable to access \"${FAXRXPATH}\""
fi
exit
More information about the asterisk-users
mailing list