Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-22-2008, 11:32 PM   #1
LQ Newbie
Registered: Apr 2002
Distribution: Linux
Posts: 14

Rep: Reputation: 0
Can I email (formatted) directly to a printer?

Can I email (formatted) directly to a printer?

I found one example on line where someone had used "lpr" in the Mail servers alias file to allow others to print directly using email. I tried this and it does work.

[my case: postfix, cups]

alias file line:
pseudoprinter: "| lpr"
And if you sent email to "" it did print the email, but it was only text, with the entire header and it is quite messy.

Is there a way to create a script which would produce a better output using the pipe?
Old 02-22-2008, 11:57 PM   #2
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,697
Blog Entries: 4

Rep: Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028Reputation: 3028
The cups system does have a lot of drivers and formatters out there; I honestly don't remember if it has one that can munch an HTML file directly. I don't think that it does.

To produce HTML output, you probably need to go through a layer of software that can parse and render the HTML page, with all of its various parts, into a printer-metafile or other output that can be printed. This being Unix/Linux, there are many choices.

HTML, by itself, is more of a page-markup language than a strict "hey printer, do exactly this" language a la PostScript. There is, in other words, more interpretation involved.
Old 02-23-2008, 12:17 AM   #3
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
You could probably take a mail-to-fax script as a starting point to put something together.
Old 02-23-2008, 10:23 PM   #4
LQ Newbie
Registered: Apr 2002
Distribution: Linux
Posts: 14

Original Poster
Rep: Reputation: 0

Well I found some ways to improve my results.

printE:        "|/usr/local/bin/a2ps -=mail"
printEs:        "|/usr/local/bin/stripmime|/usr/local/bin/a2ps"
printH:        "|html2ps|lp"

After I figured out my CUPS program had A4 as the default page size in the PPD file for the default printer (/etc/cups/ppd/<default_printer> which overrode all the other page directives I found there were about three ways I could currently make "emailing to my printer" a little better.

a2ps -=mail (any to ps) will convert the email text and the html text (not formatted) into postscript and sent it directly to my printer. It has too much data and no html formatting.

I found a perl script "stripmime" which allowed me to remove some of the headers and strip the html mime section which further improved the look of a text only email when sent to a2ps.

print H:
Using the html2ps I could send the html code directly to the default printer (using lp). Unfortunately all the headers are removed.

I found some who had a c program which compiled created html code from an email, but I couldn't get that to compile. I hope to perhaps find another way.
Old 02-25-2008, 03:58 PM   #5
LQ Newbie
Registered: Apr 2002
Distribution: Linux
Posts: 14

Original Poster
Rep: Reputation: 0
Update - Final

I found my final solution which requires a little extra work, but works fine. This whole situation was to help a friend who wanted to send messages and fun stuff home to someone who doesn't want to use a computer.

Print to PDF and email the attachment to a special email account (pdfman).
On Windows, a free nice driver is PDFCreator which also allows you to directly email the document. With it you can print any document to a PDF and then email it. You want to have the smallest file size possible when you create the PDF format. Graphics will be a problem

Set up procmail on a special account, in this case - pdfman. Within the account you need to set up the following files.

"|IFS=' '&&p=/usr/bin/procmail&&test -f $p&&exec $p -Yf-||exit 75 #pdfman"
|/usr/local/bin/pdfmime|/usr/local/bin/base64 -d|acroread -toPostScript -size letter|lp
It has only one rule (:0).

This perl script is a modified version of "stripmime" mentioned above to extract only the encoded pdf portion of the email - just modify a few variables and selection only "application/pdf" type.

base64 -d or mimencode -u
Use one or the other application which should be in your linux distribution. The commands syntax decodes the Base64 MIME encrypted enclosure.

acroread -toPostScript -size letter
Adobe Acrobat reader does have a command line option to covert to postscript. (acroread -help for other options). It unfortunately requires a writable account to create files which is why a real user account had to be created. This coverts the file to postscript which the printer can understand.

Print to the default printer which understands postscript.

The final result is that you can print almost anything you can convert to a PDF. Procmail will immediately activate when it receives the email.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Print directly to Windows network printer within a bash shell script jwillyuaz Linux - Newbie 1 02-12-2008 03:15 AM
How email OOWriter and OOCalc doc directly satimis Linux - Software 4 01-21-2008 03:49 AM
Cannot install a network printer, that is connected directly to the network. Epeescott Linux - Networking 3 03-19-2006 09:31 PM
Configuring Cups to Print directly to email. ernieg619 Linux - Networking 1 11-28-2005 04:21 PM
Random Problems, video, printer, floppy, email, installing JoeUser11 Linux - Newbie 2 03-09-2005 02:47 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration