Mailing A Fax With Mutt Does Not Succeed

Home » Asterisk Users » Mailing A Fax With Mutt Does Not Succeed
Asterisk Users 21 Comments

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@gmail.com -a /tmp/faxes/201306191111.tif

Unsuccessful Asterisk Command:
same => n,System(mutt -s “New fax” elder.arohuanca@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

21 thoughts on - Mailing A Fax With Mutt Does Not Succeed

  • Probably Asterisk does not know where mutt is, specify it’s path in your System command.

  • 1) Doesn’t mutt expect the body on stdin? (Where’s the ‘echo’ in the Asterisk command?)

    2) Is Asterisk executing as root? Does the Asterisk user ID have read access to the TIFF?

    3) If you use ‘verbose()’ instead of ‘system()’ does the command look like your shell command?

    4) Is mutt in the Asterisk user ID’s path?

    5) If you redirect the output in the system() command to a file, does that yield any clues? I.e., system(foo >/tmp/clue 2>&1)

  • Hi Andre,

    I’ve tried with:
    System(echo | /usr/bin/mutt -s “New fax” earohuanca@gmail.com -a
    ${FAXDEST}/${tempfax})

    with no success, value of SYSTEMSTATUS variable is APPERROR

    Again it works from Linux shell.

    Thanks in advance

    Elder

  • Why “echo |” ?

    Alsy are you sire of the content of ${FAXDEST} and ${tempfax}.

    Add some NoOp before.

  • Hi Andre:

    I added echo to provide STDIN, I’m sure on variable contents, please see bellow

    Hello Steve,

    1. I’ve just addd echo at my sentence, please see output bellow.
    2. Asterisk is executing as root, I think Asterisk has access to read TIF
    files since I’ve used ls, chmod, cp & mv from Asterisk’s CLI with ‘!’
    character.
    3. I don’t get you, please give some advice to try using Verbose instead System
    4. I don’t know how to get this, but I’m using /usr/bin/mutt as you can see bellow.
    5. I have redirected output of System this way : System(echo |
    /usr/bin/mutt -s “New fax” earohuanca@gmail.com -a ${FAXDEST}/${tempfax} >
    /tmp/ocurrencies.txt 2>&1), ocurrencies.txt is empty.

    DIALPLAN:
    [ Context ‘default’ created by ‘pbx_config’ ]
    ‘*95’ => 1. NoOp(trying to send a fax to an email)
    2. Set(FAXDEST=/tmp/faxes)
    3. Set(tempfax=${SHELL(ls /tmp/faxes/*.tif):11})
    4. NoOp(file name is: ${tempfax})
    5. Goto(incoming-fax,fax,7)

    [ Context ‘incoming-fax’ created by ‘pbx_config’ ]
    ‘fax’ => 1. Verbose(3,Incoming fax)

    5. ReceiveFax(${FAXDEST}/${tempfax})
    6. Verbose(3,- Fax receipt completed with status:
    ${FAXSTATUS})
    7. System(echo | /usr/bin/mutt -s “New fax”
    earohuanca@gmail.com -a ${FAXDEST}/${tempfax})
    8. NoOp(System command status is: ${SYSTEMSTATUS})
    9. Hangup()

    ASTERISK CLI OUTPUT:
    — Goto (default,*95,1)
    — Executing [*95@default:1] NoOp(“SIP/40106-00001ea1”, “trying to send a fax to an email”) in new stack
    — Executing [*95@default:2] Set(“SIP/40106-00001ea1”,
    “FAXDEST=/tmp/faxes”) in new stack
    — Executing [*95@default:3] Set(“SIP/40106-00001ea1”,
    “tempfax 1306191111.tif”) in new stack
    — Executing [*95@default:4] NoOp(“SIP/40106-00001ea1”, “file name is:
    201306191111.tif”) in new stack
    — Executing [*95@default:5] Goto(“SIP/40106-00001ea1”,
    “incoming-fax,fax,7”) in new stack
    — Goto (incoming-fax,fax,7)
    — Executing [fax@incoming-fax:7] System(“SIP/40106-00001ea1”, “echo |
    /usr/bin/mutt -s “New fax” earohuanca@gmail.com -a
    /tmp/faxes/201306191111.tif”) in new stack
    — Executing [fax@incoming-fax:8] NoOp(“SIP/40106-00001ea1”, “System command status is: APPERROR”) in new stack
    — Executing [fax@incoming-fax:9] Hangup(“SIP/40106-00001ea1”, “”) in new stack

    Elder D. Arohuanca Lima – Peru

  • More things to try:

    (1) Is there any entry in /var/log/maillog (or equivalent log file)? If so, mutt basically works and the messages should give some clues.
    (2) What happens if you call mutt without any attachments?

    I am using mutt in exactly the same way and it works.

    jg

    Am 19.06.2013 21:50, schrieb Daniel – Asterisk:

  • This worked for me:

    System(date | mutt -s “FAX from
    ${CALLERID(num)}” -a
    /var/spool/asterisk/fax/${STRFTIME(,,%Y%m%d)}-${CALLERID(num)}.tiff mail@domain)

    I don’t see any difference with you (beside the echo instead of date), so I guess you should look at the maillog to find out what is happening. Or (as I did in the end) write AGI script to send the goddamn mail using the language and method you like (I used Perl and MIME::Lite::TT::HTML), and make Asterisk call that script.

    jg
    писал 19.06.2013 23:12:

    any entry in /var/log/maillog (or equivalent log file)? If so, mutt basically works and the messages should give some clues. happens if you call mutt without any attachments?
    in exactly the same way and it works. schrieb Daniel – Asterisk:
    provide STDIN, I’m sure on variable contents, please see bellow Hello Steve, output bellow. has access to read TIF files since I’ve used ls, chmod, cp & mv from Asterisk’s CLI with ‘!’ character. some advice to try using Verbose instead System to get this, but I’m using /usr/bin/mutt as you can see bellow. have redirected output of System this way : System(echo | /usr/bin/mutt
    -s “New fax” earohuanca@gmail.com -a ${FAXDEST}/${tempfax} >
    /tmp/ocurrencies.txt 2>&1), ocurrencies.txt is empty.

    NoOp(trying to send a fax to an email)

    name is: ${tempfax})
    ‘incoming-fax’ created by ‘pbx_config’ ]
    Verbose(3,Incoming fax)

    7. System(echo | /usr/bin/mutt -s “New fax” earohuanca@gmail.com -a
    ${FAXDEST}/${tempfax})
    ${SYSTEMSTATUS})
    (default,*95,1)
    NoOp(“SIP/40106-00001ea1”, “trying to send a fax to an email”) in new stack
    “FAXDEST=/tmp/faxes”) in new stack Set(“SIP/40106-00001ea1”, “tempfax 1306191111.tif”) in new stack Executing [*95@default:4] NoOp(“SIP/40106-00001ea1”, “file name is:
    201306191111.tif”) in new stack Goto(“SIP/40106-00001ea1”, “incoming-fax,fax,7”) in new stack
    (incoming-fax,fax,7)
    System(“SIP/40106-00001ea1”, “echo | /usr/bin/mutt -s “New fax”
    earohuanca@gmail.com -a /tmp/faxes/201306191111.tif”) in new stack Executing [fax@incoming-fax:8] NoOp(“SIP/40106-00001ea1”, “System command status is: APPERROR”) in new stack
    [fax@incoming-fax:9] Hangup(“SIP/40106-00001ea1”, “”) in new stack

    1:38 PM, Andre Courchesne wrote:
    “echo |” ?
    ${tempfax}.
    2:29 PM, Daniel – Asterisk wrote:
    Andre,
    “New fax” earohuanca@gmail.com -a ${FAXDEST}/${tempfax})
    with no success, value of SYSTEMSTATUS variable is APPERROR
    Again it works from Linux shell.

    Courchesne wrote:
    does not know where mutt is, specify it’s path in your System command.

    wrote:

    the Linux shel it works, but when trying with Asterisk’s System command it doesn’t. mutt -s “New fax” earohuanca@gmail.com -a /tmp/faxes/201306191111.tif

    n,System(mutt -s “New fax” elder.arohuanca@gmail.com -a
    ${FAXDEST}/${tempfax}.tif)
    on Debian 6.0.6, Asterisk was installed by root. hint will be appreciated. Lima – Peru

  • Please don’t top-post.

    Not that it’s related to your issue…

    Since mutt is expecting the body on stdin, why not put something in like
    “Hey, you’ve got FAX.”

    This is not conclusive. The Asterisk ‘daemon’ is a separate process from your CLI process (and your shell process spawned from the CLI process). They do not ‘have to’ be executing as the same user. If the Asterisk daemon is executing as root, permissions should not be an issue — unless you’re doing something weird with /tmp/ and NFS.

    If you replace system() with verbose(), does the command you are trying to execute look correct? If you ‘copy’ the command from the Asterisk CLI and
    ‘paste’ it into a shell and execute it using sudo as the the user executing the Asterisk daemon, does it work?

    Then that should be sufficient.

    Sometimes the ‘littlest’ thing can trip you up. Usually it comes down to ownership, permissions, or environment variables.

    Not that this is the proper way to figure this out, but this is what I
    would try next in desperation — after crossing my fingers.

    (Cut and paste each line from this email to a shell.)

    AUSER=$(ps –no-heading -C asterisk –format user)

    FILE=/tmp/faxes/201306191111.tif

    MUSER

  • Hi

    Login as user asterisk and then try it

    e.g. sudo su asterisk

    and then try to execute the command.

    Last time I had this issue I had to set the shell environment for asterisk with the

    chsh

    command

  • Hello jg:

    When mutt is called from Asterisk’s dialplan there’s no output at mail.log

    When I use:
    echo | /usr/bin/mutt -s “New fax” earohuanca@gmail.com -a
    ${FAXDEST}/${tempfax} > /tmp/ocurrencias.txt 2>&1
    replacing FAXDEST and TEMPFAX with proper values, the output is as follows:

    Jun 20 16:16:16 SERVER-NAME sendmail[21276]: My unqualified host name
    (SERVER-NAME) unknown; sleeping for retry Jun 20 16:17:16 SERVER-NAME sendmail[21276]: unable to qualify my own domain name (SERVER-NAME) — using short name Jun 20 16:17:16 SERVER-NAME sendmail[21276]: r5KLHGgk021276: from=root, size6501, class=0, nrcpts=1, msgid=<20130620211615.GA21267@SERVER-NAME>, relay=root@localhost Jun 20 16:17:17 SERVER-NAME sm-mta[21285]: r5KLHGNY021285:
    from=, size6646, class=0, nrcpts=1, msgid=<20130620211615.GA21267@SERVER-NAME>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
    Jun 20 16:17:17 SERVER-NAME sendmail[21276]: r5KLHGgk021276: toearohuanca@gmail.com, ctladdr=root (0/0), delay:00:01, xdelay:00:01, mailer=relay, pri6501, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (r5KLHGNY021285 Message accepted for delivery)
    Jun 20 16:17:19 SERVER-NAME sm-mta[21287]: STARTTLS=client, relaygmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify

  • Have you tried calling a bash script that in turns calls mutt. That way you could debug much easier, adding echo to a log file.

    Sent from my iPhone

  • Hi Elder!

    I am currently busy with a problem of one of my customers. I am pretty sure that your setup requires only minor changes to make things work. I have several setups that use mutt exactly in the same way as you are trying to do (except that I am using postfix instead of sendmail, but this shouldn’t matter). I’ll have a look at your log entries tomorrow.

    jg

  • I’ though I sent this once already but here goes again…

    Have you tried changing to asterisk user and then do the same command?

    i.e.

    sudo su asterisk

    You may find that the asterisk user doesn’t have a full shell environment and you will ahve to set one using

    chsh

    Regards

    Ish

  • How about sending the whole path to mutt in the system call System(/usr/sbin/mutt) where ever it is

    —–Original Message—

  • I (sorry) haven’t read this whole thread of e-mails but I am currently using asterisk (11.3) to send received faxes via e-mail on a CentOS 6.4
    system and it’s working just fine. Perhaps my receive fax macro dialplan that I’m testing with would be helpful… I’m using mailx instead of mutt so if mutt is a requirement then I’m again sorry but perhaps mailx could be an alternative for the OP..

    [macro-ReceiveFAX]
    ; ${ARG1} – Email address(s) to send e-mail to.

    exten => s,1,Verbose(0, macro-ReceiveFAX)
    same => n,Set(CHANNEL(hangup_handler_push)

  • D> I’m trying to send a received fax with mutt, when I try it from the Linux D> shel it works, but when trying with Asterisk’s System command it doesn’t.

    Sending mail from a daemon is best done by calling /usr/sbin/sendmail directly, without relying on an MUA.

    The default mailcmd for app_voicemail is ‘/usr/sbin/sendmail -t’ You might also want to use the -oi flag.

    -JimC

  • I disagree. It’s a lot more painful to send a MIME attachment, which is what you want to do when emailing the fax image.

    Also, if you use /usr/bin/mail on a Debian-derived system, make sure you’ve installed the heirloom-mailx package rather than the standard bsd-mailx package, because the latter doesn’t handle attachments with the “-a” flag.

  • 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

  • How about:

    #!/bin/bash
    FORMAT=’%18s %-20s\n’
    (
    printf “${FORMAT}” ‘Sender:’ “${REMOTESTATIONID}”
    printf “${FORMAT}” ‘Pages:’ “${FAXPAGES}”
    printf “${FORMAT}” ‘Signal Rate:’ “${FAXBITRATE} bits/s”
    printf “${FORMAT}” ‘CallerID Number:’ “${CIDNUMBER}”
    printf “${FORMAT}” ‘CallerID Name:’ “${CIDNAME}”
    printf “${FORMAT}” ‘Call Duration:’ “${DURATION}”
    printf “${FORMAT}” ‘Status:’ “${FAXERROR}”
    ) >>${MSGFILE}

  • Thank Steve,

    That makes the section more readable and it works with /bin/ksh too.

    Cheers,

    Larry.

  • Hello everyone, I’d changed the server and mutt started working, but I’ll test your advices and wil let you lnow ass soon as I can.

    Thank you!

    Elder