HylaFAX The world's
most advanced open source fax server
|
|
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
Re: [hylafax-users] Faxmailing through external SMTP server (plus one suggestion)
El mié, 28-07-2010 a las 10:16 +0200, Marcos Lorenzo de Santiago escribió:
Hi everyone,
I'd like to share a workaround for sending faxmails through an external SMTP server, via
the program nail (heirloom-mailx), which allows files to be attached at command-line options
and sent through external SMTP server. As I saw, there's been some questions about this on the
mailing-list. I hope this helps.
I needed this feature at my job and looking at the code seemed easy to implement. Also I needed
a shell-script for processing the body of the mail and attach the file as nail program wants:
I had some bug in nailscript.sh: issue sending mails with status of sent faxes
<nailscript.sh>
#!/bin/sh
# Process STDIN to extract attachment filename and call nail with -S smtp=external_server_ip -a attachment_file
MAIL=""
TIFF2PDF="/var/spool/hylafax/bin/tiff2pdf" # tiff2pdf executable
HYLAFAX="/var/spool/hylafax" # hylafax home
SMTP=10.5.22.6 # your smtp server
while read line; do
MAIL="$MAIL$line\n"
done
MAIL=$(echo $MAIL | sed -e "s/\\\n$//" ) # remove last newline
filename=$HYLAFAX/$(echo -e $MAIL | grep tif | cut -d ' ' -f1) # get full path to the attachment
pdf="/tmp/$(basename $filename).pdf" # the filename of the converted fax to pdf
ps=""
jid=$(echo -e $MAIL | grep IDTrabajo: | cut -d ' ' -f2) # this grep depends on your language template
if [ "$pdf" == "/tmp/hylafax.pdf" ]; then
sleep 1
ps2pdf /var/spool/hylafax/$(grep docq /var/spool/hylafax/doneq/q$jid | cut -d':' -f4) /tmp/q$jid.pdf # convert to pdf
pdf="/tmp/q$jid.pdf"
fi
$TIFF2PDF -o $pdf $filename && \
echo -e "$MAIL" | /usr/bin/nail -t -S smtp=$SMTP -a $pdf && \
rm -fr $pdf # remove the pdf, leave the tif file.
</nailscript.sh>
<nailscript.sh>
#!/bin/sh
# Process STDIN to extract attachment filename and call nail with -S smtp=external_server_ip -a attachment_file
MAIL=""
TIFF2PDF="/var/spool/hylafax/bin/tiff2pdf" # tiff2pdf executable
HYLAFAX="/var/spool/hylafax" # hylafax home
SMTP=10.5.22.6 # your smtp server
while read line; do
MAIL="$MAIL$line\n"
done
MAIL=$(echo $MAIL | sed -e "s/\\\n$//" ) # remove last newline
filename=$HYLAFAX/$(echo -e $MAIL | grep tif | cut -d ' ' -f1) # get full path to the attachment
pdf="/tmp/$(basename $filename).pdf" # the filename of the converted fax to pdf
$TIFF2PDF -o $pdf $filename && \
echo -e "$MAIL" | /usr/bin/nail -t -S smtp=$SMTP -a $pdf && \
rm -fr $pdf # remove the pdf, leave the tif file.
</nailscript.sh>
[[DIFFs]]
[setup.cache]
< SENDMAIL="/usr/sbin/sendmail"
---
> SENDMAIL="/path/to/nailscript.sh"
[common-functions]
< mimeEncode $TMPDIR/body.txt $body_encoding
---
> mimeEncode $TMPDIR/body.txt "txt" #$body_encoding
[faxrcvd]
< for ft in $FILETYPE
< do
< ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
< done
---
> # for ft in $FILETYPE
> # do
> # ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
> # done
[notify]
< if [ -n "$RETURNFILETYPE" ]; then
< for ft in $RETURNFILETYPE
< do
< ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
< done
< fi
---
> #if [ -n "$RETURNFILETYPE" ]; then
> # for ft in $RETURNFILETYPE
> # do
> # ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
> # done
> #fi
[pollrcvd]
< for ft in $FILETYPE
< do
< ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
< done
---
> # for ft in $FILETYPE
> # do
> # ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
> # done
I basically removed all inline attachment and processed then after by nail. I forced mimeEncode to be ran
so that the output is just a simple "cat" of the body of the mail as nail reads it plain from STDOUT.
Also I noticed that some times the faxes has no sender in its faxinfo output:
interno1:~# faxinfo /var/spool/hylafax/recvq/fax000000038.tif
/var/spool/hylafax/recvq/fax000000038.tif:
Sender:
Pages: 1
Quality: Normal
Page: default
Received: 2010:07:28 09:33:13
TimeToRecv: 0:20
SignalRate: 14400 bit/s
DataFormat: 1-D MH
ErrCorrect: No
CallID1: 0914328098
CallID2: 80869
Is it possible that Sender may be CallID1?? I made some checks:
interno1:~# for i in /var/spool/hylafax/recvq/* ; do callid1=$(faxinfo $i | grep CallID1: | cut -d ':' -f2 | tr -d ' ' | tr -d '\n') ; sender=$(faxinfo $i | grep Sender: | cut -d':' -f2 | tr -d '\n' | tr -d ' ') ; if [ -n "$callid1" ] && [ "$callid1" == "0$sender" ]; then echo "$callid1==0$sender OK" ; elif [ 0$sender != 0 ]; then echo "$callid1==0$sender ERR" ; fi; done
0916011372==0916011372 OK
0916011372==0916011372 OK
0916011372==0916011372 OK
0957358504==0957358504 OK
0916011372==0916011372 OK
0916011372==0916011372 OK
0916499100==0916499174 ERR
0916011372==0916011372 OK
0916011372==0916011372 OK
0916011372==0916011372 OK
0916019432==0916019432 OK
0916011372==0916011372 OK
0916823336==091683396 ERR
0916011372==0916011372 OK
0915339998==0915339998 OK
0915867368==0915867368 OK
0915777672==0915777672 OK
Maybe we could add in bin/faxrcvd:
SENDER=${SENDER:-$CALLID1}
HTH
--
-----------------------------------------------------------------------
BOFH excuse #112:
The monitor is plugged into the serial port
-----------------------------------------------------------------------
Marcos Lorenzo de Santiago
Técnico de Sistemas
Departamento de Nuevas Tecnologías
Ayuntamiento de Getafe
Plaza de la Constitución 1 (28901)
Correo: marcos.lorenzo@xxxxxxxxxxxxxxx
Teléfono: 912 027 948
Móvil: 608 300 935
|
--
-----------------------------------------------------------------------
QOTD:
"If he learns from his mistakes, pretty soon he'll know
everything."
-----------------------------------------------------------------------
Marcos Lorenzo de Santiago
Técnico de Sistemas
Departamento de Nuevas Tecnologías
Ayuntamiento de Getafe
Plaza de la Constitución 1 (28901)
Correo: marcos.lorenzo@xxxxxxxxxxxxxxx
Teléfono: 912 027 948
Móvil: 608 300 935
|
Attachment:
signature.asc
Description: Esto es una parte de mensaje firmado digitalmente