Koozali.org: home of the SME Server

Make CUPS send PDF by mail

oel

Make CUPS send PDF by mail
« on: November 04, 2004, 09:56:22 AM »
Hi there,

I am trying to persuade CUPS to send the printed PDF documents to my WinXP mail account.

First problem is that cups somehow gets the WinXP username and shows it in the list of done jobs. How do I get that name to the PDF processing file (/usr/lib/cups/backend/pdf)?

I already made it, that CUPS sends an email to the SME user, but in a mixed environment I am using a sme-print-dummy-user.

Second problem is rather non-sme specific: is there a possibility to attach a file with the sendmail command. Here: attach the PDF file to the mail.

Any Ideas?

Thanx :lol:

Robert

Make CUPS send PDF by mail
« Reply #1 on: November 06, 2004, 10:34:32 AM »
I don't see how your first problem could be fixed. If everyone is using the sme-print-dummy-user account, then how could the backend know who is currently using that account?

Quote from the CUPS documentation:
"Every filter accepts exactly 6 or 7 command-line arguments:

printer job user title copies options [filename]

*   printer - The name of the printer queue (normally this is the name of the program being run)
*   job - The numeric job ID for the job being printed
*   user - The string from the originating-user-name attribute
*   title - The string from the job-name attribute
*   copies - The numeric value from the number-copies attribute
*   options - String representations of the job template attributes, separated by spaces. Boolean attributes are provided as "name" for true values and "noname" for false values. All other attributes are provided as "name=value" for single-valued attributes and "name=value1,value2,...,valueN" for set attributes
*   filename - The request file

The filename argument is only provided to the first filter in the chain; all filters must be prepared to read the print file from the standard input if the filename argument is omitted."

If everyone is using the same account, the user argument would be the same every time, so it would be useless for your purposes.

If your XP users get authenticated by samba, the user argument will be set to the samba user, and you could use that for your email addresses. The following thread, which unfortunately doesn't have the details, shows that XP users do not need a Unix account on the SME Server for that:
http://forums.contribs.org/index.php?topic=19406.0

Alternatively, you might be able to use a trick with one of the other arguments passed to the pdf backend, namely the title argument. If you look in the page_log for cups and you see sensible job-names (i.e. not crap like "smbprt.xxx"), you might be able to hide the email address there. I.e. name file "user@domain.tld", send it to pdf-printer, make pdf backend send mail to $3.

Regarding your second problem, I found the following script by googling:

#!/bin/bash
#
# Script: sendfile
#
# Purpose: Send the specified file via email as a MIME
#          attachment to the specified address.
#
# Author: Anthony E. Greene <agreene pobox com>
#
# License: GPL <http://www.gnu.org/>
#
# Note: This script does not include any error checking, so
#       it should only be called from within other scripts.
#       The correct syntax for using this script is:
#
# sendfile.sh user domain filename | /path/to/sendmail -oi -t
#

# First we set up some global variables.
# Some code should be added to verify the commandline arguments.
sender=me myisp domain
recipient=$1
filename=$2
basefile=/bin/basename $filename

echo From: $sender
echo To: $recipient
echo Subject: File $basefile
echo MIME-Version: 1.0
echo "Content-Type: multipart/mixed; Boundary=\"sendfile-attachment-boundary\""
echo
echo --sendfile-attachment-boundary
echo 'Content-Type: text/plain; charset=us-ascii'
echo
echo This is a MIME encoded message. If your mail software
echo cannot properly handle the attached file, you may need
echo to get a MIME-aware mailer.
echo
echo --sendfile-attachment-boundary
echo "Content-Type: application/octet-stream; name=\"$basefile\""
echo Content-Transfer-Encoding: base64
echo "Content-Disposition: attachment; filename=\"$basefile\""
echo
/usr/bin/mimencode $filename
echo --sendfile-attachment-boundary--

Note that  it uses the mimencode command, which is provided by the metamail package.

P.S. I'm interested in your current pdf-by-email solution. Could you send it to me by email? My email address is in the docs for e-smith-cups.

oel

Make CUPS send PDF by mail
« Reply #2 on: November 06, 2004, 10:14:55 PM »
thanks robert,

you gave me some hints for a sme only solution. which means, that cups/samba will send the printed pdf by mail to the user which printed it.

take the file "/usr/lib/cups/backend/pdf" an add the follwoing lines to the end before "exit 0"

Code: [Select]

uuencode "$OUTPUTFILENAME" "$PRINTTIME.pdf" > tempfile.tmp
cat tempfile.tmp | /bin/mail $2@domain.tld
rm tempfile.tmp
rm $OUTPUTFILENAME


that's basically all. i am not a linux or bash guru so this might be done in a much better style, but right now i just does what i need - for sme world only though.

when you look at the list of done jobs in the cups web interface you will see the name of the winxp user - although it is an other name than the sme-print-dummy. so maybe someone knows where to get that name from to put it in the place of the above used
Code: [Select]
$2 variable.

cheers mates[/b]

oel

Make CUPS send PDF by mail
« Reply #3 on: November 08, 2004, 10:11:14 AM »
ok, i just discovered, the following:

when i connect to the pdf printer from a windows box via a usual network printer, cups will use the name of the connected user (i.e. the user, that has already network connects under his name). that will also be the name whioch i see in the list of completed jobs in the cups interface.

when i connect via http (i.e. http://sme:631/printers/pdfprinter) windows will ask me for a user account. here i took that sme-print-dummy-account. nevertheless cups will show the real windows user name in the list of completed jobs. and that's the name i need for proper mailing.

btw, that variable is called "job-originating-user-name". you can see its value if you activate the print banner at your pdfprinter. note: this will only work if you connected the printer with "http://...."

guest22

Make CUPS send PDF by mail
« Reply #4 on: November 08, 2004, 10:26:56 AM »
Interesting...

Any chance you can create a how-to and make the scipts/files available? Maybe someone can create a nice contrib RPM ;-)

Cheers,
RequestedDeletion

oel

Make CUPS send PDF by mail
« Reply #5 on: November 17, 2004, 09:54:21 AM »
hi,

first of all, we (robert an i) solved the problem.

making a rpm is far beyond my knowledge of linux, so i will try to make an understandable howto in this forum.

the task was:

install cups and the cups pdf writer on sme 6.0.1 (following the great howto of robert van den aker). then set up a sme user called "print".
the goal was to makle sme send the generated pdf to the WINXP user. let's say i am bill.gates (that's my windows xp login name). an i want sme to send me the pdf to my email account on i.e. an exchange mail server (don't ask why i would use that one).


the way i did it:

after installing cups and pdf printer i set up user "print" with password "print".

then i edited /usr/lib/cups/backend/pdf. there i added the following line at the top where the variables are defined:

Code: [Select]

DOMAIN="@microsoft.com"
WINUSERNAME=lpstat -u |awk '{print $2}'


with that code i have the login username of the windows user. combined with the domain i have a real email address

now i only have to tell the script what to do with the pdf. so right before the last line (exit0) i inserted:

Code: [Select]

uuencode "$OUTPUTFILENAME" "$PRINTTIME.pdf" > tempfile.tmp
cat tempfile.tmp | /bin/mail -s "PDF printout $PRINTTIME" $WINUSERNAME$DOMAIN
[/b]

that's it on sme's side.

on windows side you have to install a networkprinter. !imaportant! use a http:// printer. in this case i connected to the sme pdfprinter with this:

http://sme:631/printers/pdfprinter (assuming my box is called "sme" and the pdf-printer was named "pdfprinter"). windows then asks for the username. here you give him the print-dumme-user "print" with the password "print". remember, the script won't use that name, it will use the name of the winxp login.

so, after telling windows to use athe first apple PS printer as a driver, everything works perfectly.

cheers, oel


ps: the only constraint is, that cups cannot handle special characters (like we use in germany or the scandinavians), that means the username you login with at your win box should be in "clean" letters.

Offline MSmith

  • *
  • 675
  • +0/-0
This is a very interesting technical exercise ...
« Reply #6 on: November 23, 2004, 04:18:58 PM »
... but wouldn't it be easier simply to use the excellent and free PDFCreator?

http://sourceforge.net/projects/pdfcreator/
...

oel

Make CUPS send PDF by mail
« Reply #7 on: November 23, 2004, 08:22:58 PM »
pdfcreator is a very good project - and we actually first tried that way, because it is easier (at first).

but we are working on a windows 2003 terminal server, and pdfcreator wouldn't work in a terminal server session. so we needed another solution. the good thing with sme is, that all you have to do is to attach a http-printer, no software installation required.

 :-)