Local IMAP mail setup for Laptops

Cyrus

Cyrus is one of the most widely used IMAP/POP servers. Cyrus is appreciated for virtualisation of mailboxes and cool stuff like server side filtering (sieve) or shared folders. It is frequently used in universities. This will be used to keep the mails of the local users on local machine.

Sendmail

You have to configure your mail transfer agent to deliver your local messages in your Cyrus mailbox.

Sendmail is the most popular mail transfer agent (MTA) on the Internet. Its popularity is due in part to its position as the standard MTA under most variants of the Unix and other Unix-like operating system.

Sendmail supports a variety of mail transfer protocols, including SMTP, ESMTP, DECnet's mail 11, HylaFax, QuickPage and UUCP. Additionally, Sendmail v8.12 as of September 2001 introduced support for milters - external mail filtering programs that can participate in each step of the SMTP conversation.

Bind

BIND is an implementation of the Domain Name System (DNS) protocols.

The BIND software distribution contains three parts:

  • A Domain Name System server. This is a program called "named", which is pronounced "name-dee" and stands for "name daemon". It answers questions that are sent to it, following the rules specified in the DNS protocol standards. You can provide DNS service on the internet by installing this software on a server computer and giving it correct information about your domain names.

  • A Domain Name System "resolver library". A "resolver" is a program that resolves questions about names by sending those questions to appropriate servers and responding appropriately to the servers' replies. A "resolver library" is a collection of software components that a programmer can add to software being developed, which will give that software the ability to resolve names. For example, a programmer who was programming a new web browser does not need to create the part of it that looks up names in DNS; he or she can plug in the resolver library and then send questions to the library software components. This saves time (the programmer does not need to re-invent that particular wheel) and helps ensure that the new browser correctly follows the DNS standards.

  • Software tools for testing servers. These are the tools that we use for testing and we include them in the distribution in case you would like to do your own testing, perhaps to make sure your server configuration is working properly.

Fetchmail

Fetchmail is a full-featured, robust, remote-mail retrieval and forwarding utility intended to be used over on-demand TCP/IP links (such as SLIP or PPP connections). It supports every remote-mail protocol now in use on the Internet: POP2, POP3, RPOP, APOP, KPOP, all flavors of IMAP, ETRN, and ODMR. It can even support IPv6 and IPSEC.

Fetchmail retrieves mail from remote mail servers and forwards it via SMTP, so it can then be read by normal mail user agents such as mutt, elm(1) or BSD Mail. It allows all your system MTA's filtering, forwarding, and aliasing facilities to work just as they would on normal mail.

Fetchmail offers better protection against password-sniffing than any other Unix remote-mail client. It supports APOP, KPOP, OTP, Compuserve RPA, Microsoft NTLM, and IMAP RFC1731 encrypted authentication methods including CRAM-MD5 to avoid sending passwords en clair. It can be configured to upport end-to-end encryption via tunneling with ssh, the Secure Shell.

Fetchmail can be used as a POP/IMAP-to-SMTP gateway for an entire DNS domain, collecting mail from a single drop box on an ISP and SMTP-forwarding it based on header addresses. (We don't really recommend this, though, as it may lose important envelope-header information. ETRN or a UUCP connection is better.)

References :
http://fetchmail.berlios.de/

UUCP and rmail

UUCP can transfer anything. It can be told to transfer some data to remote system and execute some program on that remote system having this data as input. Or in back direction -- sending output of remote command to local system.

Rmail command is a traditional way for transmitting mail over uucp. One system prepares email message and tells uucp to deliver it to remote system and call `rmail' program there, so this program will read the message and deliver it using local (from the remote side) ways. Trivial rmail "program" is distributed with Postfix. It is a simple shell script that calls local /usr/sbin/sendmail with appropriate arguments, giving it the input received from remote side.

May be. The `server' is a system name configured in local /etc/uucp/sys file. If you name it `server.fq.dn', then you should use this name when invoking uucico (or uux for queuing a command for a system, or uucp for simple file transfer, or uustat for displaying a queue and so on).

UUCP (UNIX-to-UNIX Copy Protocol) is a set of unix program for copying (sending) files between different UNIX systems and for sending commands to be executed on another system. The main UUCP commands (each supported by a UUCP program) are:

  • uucp, which requests the copying of a specific file to another specified system.

  • uux, which sends a UNIX command to another system where it is queued for execution

  • uucico, which runs on a UNIX system as the program that carries out the copying and initiates execution of the commands that have been sent. Typically, this program is run at various times of day; meanwhile, the copy (uucp) and command (uux) requests are queued until the uucico program is run.

  • uuxqt, which executes the commands sent by uux, usually after being started by the uucico program

The uucico programs are the programs that actually communicate across a network.

There are several network protocols (variations on packet size and error-checking) that can be used by uucico programs, depending on the kinds of carrier networks being used.

Configuring UUCP for Merce laptop user

Note :

Here example of Ram's laptop UUCP configuration is used as example.

  • Hostname of the system : kmram.merceworld.com
  • uucpqueue name : kmram.mercewormd.com
  • uucp queue created on mx server : pacific (uucp-in1.pub.merceworld.com).
  • One more account is created on atlantic (uucp-in2.pub.merceworld.com) but is not explained here. It is similar to configuration done on pacific. Only need to done the server side uucp queue creating and creating alias similar to pacific. We have sent one copy of Ram's mail to newly created uucp queue and other to his regular queue.

    Required configuration files to setup IMAP mails:

    Cyrus

     
    /etc/imapd.conf
    /etc/cyrus.conf
    /etc/default/saslauthd
    

    Sendmail

    /etc/mail/sendmail.mc
    /etc/mail/sendmail.conf
    

    UUCP

    /user/sbin/uusched
    /etc/uucp/sys
    

    Installing required packages in Ubuntu

    Cyrus

    $ sudo apt-get install cyrus-admin-2.2 cyrus-clients-2.2 cyrus-imapd-2.2 sasl2-bin cyrus-pop3d-2.2 cyrus-doc-2.2 cyrus-sasl2-doc
    
    On Postfix Configuration Screen select No configuration and hit . 
    

    Sendmail

    sudo apt-get install sendmail-base sendmail-bin sendmail-cf sendmail-doc 

    BIND

    $ sudo apt-get install bind9 bind9-doc
    

    Fetchmail

    $ sudo apt-get install fetchmail
    

    UUCP and rmail

    $ sudo apt-get install uucp rmail
    

    Thunderbird

    $sudo apt-get install thunderbird
    

    Configuration

    Cyrus

    Please check the configuration of the following parameters in config files of cyrus.

    vim /etc/default/saslauthd
    
    # Other options (default: -c -m /var/run/saslauthd)
    # Should saslauthd run automatically on startup? (default: no)
    START=yes
    
    # Which authentication mechanisms should saslauthd use? (default: pam)
    MECHANISMS="pam"
    
    # Additional options for this mechanism. (default: none)
    MECH_OPTIONS=""
    
    # How many saslauthd processes should we run? (default: 5)
    THREADS=5
    
    vim /etc/cyrus.conf  
    

    Uncomment "imap" line as shown below.

    # most services also accept -U (limit number of reuses) and -T (timeout)
    SERVICES {
    	# --- Normal cyrus spool, or Murder backends ---
    	# add or remove based on preferences
    	imap		cmd="imapd -U 30" listen="imap" prefork=0 maxchild=100
    	#imaps		cmd="imapd -s -U 30" listen="imaps" prefork=0 maxchild=100
    	pop3		cmd="pop3d -U 30" listen="pop3" prefork=0 maxchild=50
    	#pop3s		cmd="pop3d -s -U 30" listen="pop3s" prefork=0 maxchild=50
    	#nntp		cmd="nntpd -U 30" listen="nntp" prefork=0 maxchild=100
    	#nntps		cmd="nntpd -s -U 30" listen="nntps" prefork=0 maxchild=100
    
    ....
    	# ----------------------------------------------
    }
    
    vim /etc/imapd.conf
    
    # UNIX Hierarchy Convention
    unixhierarchysep: no
    
    # and including 2.2.12-4.
    lmtp_downcase_rcpt: yes
    
    # Uncomment the following and add the space-separated users who 
    # have admin rights for all services.
    # admins: cyrus
    
    # Space-separated list of users that have imapd "admin" status, in
    # addition to those in the admins: entry above
    imap_admins: cyrus
    
    # Allow plaintext logins by default (SASL PLAIN)
    allowplaintext: yes
    
    #
    # SASL library options (these are handled directly by the SASL libraries,
    # refer to SASL documentation for an up-to-date list of these)
    #
    sasl_pwcheck_method: saslauthd
    

    Cyrus Mailbox creation

    Login with "root" and set Cyrus "password" first.

    # passwd cyrus
    
    Enter new UNIX password: TYPE YOUR CYRUS PASSWORD HERE
    Retype new UNIX password: RETYPE YOUR CYRUS PASSWORD
    

    Creating user mail box

    To create user mail box you need to login with cyrus user and use cyradm command (Note:- For example here I took "kmram" user name).

    su - cyrus
    
    Syntax :-
           localhost>cm user.username
    
    $ cyradm --user cyrus -auth plain localhost
      password : 
      IMAP Password: 
    	localhost>cm user.kmram
    
    

    Here you can get full description of the available commands by typing help.

    Dot not forget the prefix "user." or the mailbox created will be considered as a shared mailbox.

    Test that your cyrus user works correctly or not?

    $ telnet localhost imap
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    OK kmram.merceworld.com Cyrus IMAP4 v2.2.13-Debian-2.2.13-14ubuntu3 server ready
    imap login kmram passowrd 
    imap OK User logged in 
    

    If it does not work check /var/log/mail.log for troubleshoot.

    Sendmail

    vim /etc/mail/sendmail.mc
    

    Make changes to sendmail.mc configuration file as shown below

     
    DAEMON_NETMODE="Dynamic";
    QUEUE_INTERVAL="5m";
    MSP_MODE="Daemon";
    MSP_INTERVAL="1m";
    
    /etc/mail/sendmail.mc 
    FEATURE(`no_default_msa')dnl
    FEATURE(`use_cw_file')dnl
    FEATURE(`accept_unresolvable_domains')dnl
    dnl DAEMON_OPTIONS(`Family=inet, Name=MTA-v6, Port=smtp, Addr=127.0.0.1')dnl
    DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
    DAEMON_OPTIONS(`Family=inet,  Name=MSP-v4, Port=submission, Addr=127.0.0.1')dnl
    
    dnl define(`LUSER_RELAY', `local:cyrusv2')dnl
    FEATURE(`always_add_domain')dnl
    dnl MASQUERADE_AS(`merceworld.com')dnl
    dnl define(`confDOMAIN_NAME', `merceworld.com')dnl
    define(`ALIAS_FILE',`/etc/aliases')
    define(`confBIND_OPTS', `WorkAroundBrokenAAAA')dnl
    define(`confLOCAL_MAILER',`cyrusv2')dnl
    define(`confCON_EXPENSIVE',`False')dnl
    define(`confQUEUE_LA',`40')dnl
    define(`confREFUSE_LA',`60')dnl
    define(`confMIN_QUEUE_AGE',`2m')dnl
    define(`confMAX_DAEMON_CHILDREN',`20')dnl
    dnl define(`confMIN_FREE_BLOCKS',`250000')dnl Minimum number of free blocks needed to accept new mail
    dnl define(`confMAX_MESSAGE_SIZE',`50000000')dnl Maximum size of the message to accept
    define(`UUCP_MAILER_MAX', `50000000')
    define(`confTO_IDENT', `0')dnl
    define(`SMART_HOST',`uucp-dom:uucp-in1.pub.merceworld.com')dnl
    define(`CYRUSV2_MAILER_ARGS',`FILE /var/run/cyrus/socket/lmtp')dnl
    FEATURE(`smrsh')dnl
    dnl FEATURE(`allmasquerade')dnl
    dnl FEATURE(`masquerade_envelope')dnl
    dnl FEATURE(`virtusertable', `hash /etc/mail/virtusertable')dnl
    
    MAILER_DEFINITIONS
    MAILER(`local')dnl
    MAILER(`smtp')dnl
    MAILER(`cyrusv2')dnl
    MAILER(`uucp')dnl
    
    dnl MODIFY_MAILER_FLAGS(`SMTP',`+e')dnl
    dnl MODIFY_MAILER_FLAGS(`UUCP',`+e')dnl
    dnl MODIFY_MAILER_FLAGS(`CYRUSV2',`+we')dnl
    dnl MODIFY_MAILER_FLAGS(`ESMTP',`+e')dnl
    
    LOCAL_CONFIG
    C{LOCALUSER}kmram km.ram 
    C{LOCALDOMAIN}merceworld.com 
    
    LOCAL_RULE_0
    R$={LOCALUSER} < @ $={LOCALDOMAIN} >		 $#cyrusv2 $: kmram 
    R$={LOCALUSER} < @ $={LOCALDOMAIN} . >		 $#cyrusv2 $: kmram 
    
    

    Note : LOCAL_CONFIG rule is to send a mail that are intended to send to km.ram@merceworld.com to local cyrus mail box of kmram.

    Converting sendmail.mc to sendmail.cf

    $ cd /etc/mail/
    $ ls -l sendmail.cf
    $ mkdir RCS
    $ ci -l sendmail.cf
    $ m4 sendmail.mc > /var/tmp/sendmail.cf
    $ mv /var/tmp/sendmail.cf /etc/mail/
    

    Restart the sendmail :

    $ /etc/init.d/sendmail restart
    

    UUCP Configuration

    Login with uucp user to create UUCP ssh key.Note that use blank passphrase for uucp key.

     $ su uucp
     $ sh-keygen -t dsa -b 1024 -C "UUCP user key for kmram.merceworld.com"
    

    For creating a ssh tunnel we need to add a uucp ssh key to server. Copy uucp id_dsa.pub key to server's /var/tmp using scp command. Add this key to uucptunnel user's authorized_keys file on server (pacific.merceworld.com).

    Login in to server (pacific.merceworld.com)

    Creating uucp queue on the server for laptop user

    Add laptop users uucp ssh key to uucptunnel user

    $ su – uucptunnel
    $ cd .ssh/
    $ cat /var/tmp/id_dsa.pub >> authorized_keys
    $ chown uucptunnel.uucptunnel authorized_keys
    $ chmod 640 authorized_keys
    

    Logout from uucptunnel users

    Add user queue parameters in /etc/uucp/sys at bottom.

    $ cd /etc/uucp
    $ ci -l sys
    $ chown uucp.uucp sys
    $ chmod 644 sys
    $ vim sys
    
          System kmram.merceworld.com
          myname uucp-in1.pub.merceworld.com
          called-login kmram.merceworld.com
          time any 
          commands rmail
    

    Add user uucp password in /etc/uucp/passwd at bottom.

    $ cd /etc/uucp
    $ ls -l passwd
    $ ci -l passwd
    $ chown root.uucp passwd
    $ chmod 640 passwd
    $ vim passwd
            
              kmram.merceworld.com password
    

    Add user alias in /etc/aliases file.

    If you want to forward one copy of mail to current merce queue and one to new uucp queue, then make changes in /etc/aliases and /etc/mail/virtusrtable.

    Add/modify entry of kmram in /etc/aliases

    as below.

    $ cd /etc
    $ ci -l aliases
    $ chown root.root aliases
    $ chmod 644 aliases
    
    kram: km.ram@arctic.merceworld.com,"|/usr/local/bin/viauux kmram.merceworld.com km.ram@merceworld.com"
    
    

    Add this entry in /etc/mail/virtusertable.

    $ cd /etc/mail
    $ ci -l virtusertable
    $ chown root.root virtusertable
    $ chmod 644 virtusertable
    $ vim virtusertable
    
             km.ram@merceworld.com                  kram
             kmram@merceworld.com                   kram
    
    

    If you want to forward mail to only uucp queue, then do the following.

    $ cd /etc/mail
    $ ci -l virtusertable
    $ chown root.root virtusertable
    $ chmod 644 virtusertable
    $ vim virtusertable
        
             km.ram@merceworld.com        uucp-dom:kmram.merceworld.com
    
    

    Rebuilding virtusertable and aliases

    $ cd /etc/mail
    $ ci -l  /etc/mail/virtusertable.db
    $ chown root.root virtusertable.db
    $ chown 640 virtusertable,db
    $ makemap hash /var/tmp/virtusertable.db < /etc/mail/virtusertable
    $ mv /var/tmp/virtusertable.db /etc/mail/
    
    $newaliases
    
    

    On user's Laptop

    Add entry in /etc/uucp/sys

    $ cd /etc/uucp
    $ vim sys
    
    	system uucp-in1.pub.merceworld.com  
    	myname kmram.merceworld.com 
    	port type tcp 
    	port service 7071
    	address localhost
    	chat ogin: kmram.merceworld.com word: password 
    	time any 
    	chat-timeout 300 
    	protocol t
    
    

    uusched script

    This script actually activate the send/receive mail facility for UUCP. This script creates a ssh tunnel to the uucp-in1.pub.merceworld.com futher communication will do over this ssh tunnel.

    Take a backup of existing /usr/sbin/uusched file and copy the uusched sccript provided with this document in to /usr/local/sbin and create a symlink

    .

    Copy the uusched file from /var/tmp and set the permission for /usr/local/sbin/uusched

    $ cp /var/tmp/uusched /usr/local/sbin/uusched
    $ chown uucp.uucp /usr/local/sbin/uusched
    $ chmod 510 /usr/local/sbin/uusched
    
    $ cd /usr/sbin/
    $ mv uusched uusched.ori
    $ ln -s /usr/local/sbin/uusched uusched
    

    Adding uusched script in uucp cron

      
    $ su - uucp
    $ crontab -e
    

    Add the following in uucp crontab

    # Enable this cronjob for uusched
    */5 * * * * /usr/sbin/uusched >/var/tmp/uusched.out 2>/var/tmp/uusched.err
    

    Configuration on Apps

    We need to add the laptop user entry in /etc/sysconfig/laptopuser file for the user. So when any mail is sent from Merce office will sent to server(pacific.merceworld.com)UUCP queue rather than the local cyrus inbox's of user.

    Restart the sendmail

    .

    Configure Laptop user Thunderbird

    Configuring thunderbird -
    account setting -
    1. New Account Setup
    New E-mail account

    2. Identity
    your name : K M Ram
    Email-address : km.ram@merceworld.com

    3. Server Information
    Select type : IMAP
    Incomming server : localhost

    4. User names
    Incomming User Name : kmram

    5. Account Name :
    account name : km.ram@merceworld.com

    6. Click "Finish".

AttachmentSize
Laptop-Mail-setup.txt18.74 KB
uusched.bz21.85 KB

Some more feedback

After the saslauthd etc are configured, the saslauthd must be started
before the cyradm connection can be done. You need to add an instruction
to do an /etc/init.d/saslauthd restart

The cyradm command can be run as any user --- you don't have to su cyrus
to run it. The --user cyrus parameters on the command line take care of
what user it connects as.

The cyradm command-line has -auth but I guess it should be --auth.

The testing of the IMAP login has "passowrd". Fix the spelling. Also
give an example: "Suppose kmram's password is kabba123lla, then enter the
following line..."

The IMAP testing shows how to login, but does not show how to log
out. Normal commands like "quit" or "exit" do not work. I had to
forcibly come to the Telnet command prompt and break out.

The sendmail.mc instructions are very confusing. Are you listing the
changes to be made, or are you listing the changed file here? Why is
there the line "/etc/mail/sendmail.mc" after four lines of content?

For sendmail.mc, cyrus.conf and imapd.conf, identify the lines to be
changed, and specify the changes to be done for each line. Do not just
paste a block of lines into this page --- it gives the wrong impression
that you are giving the complete file's content here.

On the laptop, for UUCP configuration, you are adding only uucp-in1 into
the sys file. You need to add uucp-in2 to the file too. The laptop must
poll both public UUCP servers.

The sendmail config has a problem: it does not recognize starcomsoftware
as a valid local domain. This won't do --- we still keep getting mails
sent to our @starcomsoftware email address.

Your list of files to be edited includes /etc/mail/sendmail.conf. But
your process does not describe any changes to be made to that file. In
fact, I set up the entire email setup on my laptop without touching
sendmail.conf.

The list of tasks should also include making an entry to /etc/aliases
on the laptop, pointing root to the local user. This will allow system
messages from the laptop to reach the local user. Run "newaliases"
on the laptop after this.

Some errors/questions

Dear guys,

The Thunderbird setup instructions seem totally off. The "Your name" field in the Identity section should contain your full name (the software even gives "John Smith" as an example). You've written a one-word "kmram" here. It should have been "K M Ram". Setting this correctly is important because this is what the recipient of your official emails sees when you write to them. Most of you set this wrongly, and you either have some abbreviated nonsense in your From addresses, or you have your name in all lower-case letters, etc. If you don't respect your own name, do you think others will?

Similarly, K M Ram's email address in Thunderbird should be "km.ram@merceworld.com" not the short form of his email address. This is another error I constantly see in mails I get from you... you don't set your more readable long email address in your MUA.

The Thunderbird account name should be "Office email" or some such thing, most certainly not the email address. This too is given in the examples that Tbird displays: "For example, Work Account, Home Account, etc."

There is a "mercewormd.com" at one place. Please fix it.

Your comment on Postfix configuration screen seems to indicate that the laptop will continue to have Postfix, but you'll set its configuration to not let it execute. This is dangerous. Please use

apt-get --purge remove postfix

and remove Postfix completely from the laptop.

In the documentation, please replace "Bind" with "BIND" everywhere --- BIND is an abbreviation, not a proper-noun.

In the section on "Creating user mailbox", there is a grey-coloured box where you show how the cyradm commands will look. In that box, there is a portion saying "Syntax:- " something-or-other, and that part seems to be an example. Shouldn't the example be outside the grey box? Or does the user need to type in those things too? Also, the Syntax portion seems to mention a command

cm user.

Don't we have to give a username after the "user."?

I was under the impression that creating a mailbox in Cyrus includes setting ACL rights for that user for his own mailbox, and then granting the "cyrus" user rights to the user's mailbox, so that lmtpd can deliver mails to him. I don't see those commands. Aren't they needed?

Reading the documentation, it is not at all clear that the engineer must replace "password" with something secret and non-obvious for the UUCP passwords. Please make this clear.

Your command examples all show them being typed in at the dollar prompt. Shouldn't they be shown as being typed at a hash prompt? I think practically all these commands will need super-user access.

For the UUCP config files, one important thing to take care of is their permissions and ownership. If you create these files as root and don't change ownership, then UUCP won't work. Similarly, if any file is supposed to contain a password, its permissions should be set so that only UUCP can read them, so that global read is not possible. I think those instructions should be included here.

And lastly, it would be very helpful if you could attach a tar.gz file to this page, containing samples for all the config files that the engineer must edit to set up the laptop-side of the mail setup.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.