Results 1 to 2 of 2

Thread: [solved] printing email automatically

  1. #1
    Join Date
    Oct 2008

    [solved] printing email automatically

    Email to Printer Gateway

    Jason Ellison

    I'm posting this here because I read an unanswered post describing exactly what I wanted to do.

    printing email automatically

    Well I did it and here is how...

    This document covers setting up a Linux box to download email from a POP3 account on a Microsoft Exchange server and printing it to a network printer. When the emails are downloaded they are deleted. Already read emails are also deleted. Only new emails will be printed.

    This example was done using Slackware 12.0.0 but it would work with a few changes on Ubuntu.

    Setup printer in cups

    chmod 755 /etc/rc.d/rc.cups
    /etc/rc.d/rc.cups start

    add the printer, print a test page, and make it the default or specify it in the lpr command.

    Create user

    root@monitor:~# adduser
    Login name for new user []: printemail
    User ID ('UID') [ defaults to next available ]:
    Initial group [ users ]:
    Additional groups (comma separated) []:
    Home directory [ /home/printemail ]
    Shell [ /bin/bash ] /bin/false
    - Warning: /bin/false is not in /etc/shells (potential problem using FTP)
    Do you wish to change the shell ? (Y/n) n
    Expiry date (YYYY-MM-DD) []:
    New account will be created as follows:
    Login name.......: printemail
    UID..............: [ Next available ]
    Initial group....: users
    Additional groups: [ None ]
    Home directory...: /home/printemail
    Shell............: /bin/false
    Expiry date......: [ Never ]
    This is it... if you want to bail out, hit Control-C. Otherwise, press
    ENTER to go ahead and make the account.
    Creating new account...
    Changing the user information for printemail
    Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
    Changing password for printemail
    Enter the new password (minimum of 5, maximum of 127 characters)
    Please use a combination of upper and lower case letters and numbers.
    New password:
    Bad password: too short.
    Warning: weak password (enter it again to use it anyway).
    New password:
    Re-enter new password:
    Password changed.
    Account setup complete.

    root@monitor:~# usermod -p R@nd0Mp@ssw0rd printemail

    root@monitor:~# usermod -L printemail

    I disable the account from remote logins for security. Slackware's cron daemon does not
    use the users shell anyway.

    Configure Fetchmail

    Use fetchmail to obtain mail from remote locations.

    printemail@monitor:~$ cat .fetchmailrc
    poll with proto POP3 and options no dns
    user 'support' there with password 's3cr3t' is 'printemail' here and wants mda "/usr/bin/procmail -d %T" options nokeep flush

    printemail@monitor:~$ chmod 0710 .fetchmailrc

    Script mailx to print email

    Create a mailx command file that:

    a. prints the first email
    b. deletes the first email
    c. quits the program

    * note: I tried to do this using mailrc but the program would not respect the quit command
    when there were more than 2 emails in the mailbox !*?

    set cmd=/usr/bin/lpr
    set page=yes
    set pipe-text/html="lynx -dump -force_html /dev/stdin"
    #mailrc would not respect the quit command
    folder /var/mail/printemail
    pipe 1 /usr/bin/lpr
    delete 1

    Then write a bash script to run mailx until no new mail exists in the mailbox.

    #fetch the new mail
    /usr/bin/fetchmail > /dev/null
    #print all new mail
    while ( /usr/bin/mailx -e > /dev/null 2>&1 ); do
    /usr/bin/mailx -B < ~/.mailcmd ;
    sleep 1 ;

    Schedule the job

    Finally you would want to cron the job so that it runs every five minutes.

    root@nebula:~# crontab -l | grep print_email
    # print_email every five minutes
    */5 * * * * /usr/local/bin/ 1> /dev/null

  2. #2
    Join Date
    Mar 2013

    Re: [RE-OPENED] printing email automatically

    Hi infotek,

    I'm not ubuntu user, but I'ma debian user (newbe)
    I've follow your step, but I'm little confusing:

    1- Configure Fetchmail

    this is done in the user printemail, and the configuration of global fetchmail?

    Script mailx to print email
    I've crated the file .mailcmd in root user folder is this correct?
    Who is the owner of

    3- Schedule the job
    Finally your scheduled job is under root.

    Thanks for your reply

    Last edited by Andre81; March 8th, 2013 at 03:51 PM.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts