old-www/LDP/Mobile-Guide/html/mobile-guide-p5c1s3-e-mail....

966 lines
17 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>E-Mail</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Linux on the Road"
HREF="index.html"><LINK
REL="UP"
TITLE="Different Environments"
HREF="mobile-guide-p5c1-different-environments.html"><LINK
REL="PREVIOUS"
TITLE="Configuration Tools"
HREF="mobile-guide-p5c1s2-configuration-tools.html"><LINK
REL="NEXT"
TITLE="Data Transport Between Different Machines (Synchronization)"
HREF="mobile-guide-p5c1s3-data-transport.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Linux on the Road: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="mobile-guide-p5c1s2-configuration-tools.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 15. Different Environments</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="mobile-guide-p5c1s3-data-transport.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="mobile-guide-p5c1s3-e-mail"
></A
>15.3. E-Mail</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN4067"
></A
>15.3.1. Introduction</H2
><P
>&#13; A short introduction about how to setup email on a laptop used at home
(dial-up) and work (ethernet) by Peter Englmaier &#60;ppe_AT_pa.uky.edu&#62;:
</P
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN4070"
></A
>15.3.1.1. Features</H3
><P
>&#13; As a laptop user, I have special demands for my email setup. The setup
described below, enables me to:
</P
><P
>&#13;
<P
></P
><UL
><LI
><P
>&#13; Read my email from <EM
>home</EM
> using a POP email server,
which is supplied by my university, but could also be setup on a
<EM
>work</EM
> place computer.
</P
></LI
><LI
><P
>&#13; Write email from home with the <EM
>right</EM
> return address
in the email (which does not mention my computer name).
</P
></LI
><LI
><P
>&#13; Read/write my email while working on a workstation without access to my
laptop or the POP email server (as a backup).
</P
></LI
><LI
><P
>&#13; Read my email while working on my laptop connected to the ethernet of
our institut.
</P
></LI
><LI
><P
>&#13; Direct email while connected via ethernet (faster than the fetchmail
method).
</P
></LI
><LI
><P
>&#13; Indirect email (over pop mail server) while not connected to the
ethernet at work (either at home via modem or somewhere else via
ethernet).
</P
></LI
><LI
><P
>&#13; Use any emailer, e.g. <B
CLASS="command"
>elm</B
> or the simple
<B
CLASS="command"
>mail</B
> command.
</P
></LI
><LI
><P
>&#13; Sort incoming email, delete spam, split email-collections (digests)
into seperate emails
</P
></LI
></UL
>
</P
><P
>&#13; The configuration is based on <B
CLASS="command"
>sendmail</B
>,
<B
CLASS="command"
>fetchmail</B
>, and a <EM
>remote pop
account</EM
> for email.
</P
></DIV
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN4100"
></A
>15.3.1.2. Configuration of sendmail</H3
><P
>&#13; This is the most complicated part. Having installed the
<B
CLASS="command"
>sendmail-cf</B
> package, I created a file named
<TT
CLASS="filename"
>/usr/lib/sendmail-cf/laptop.mc</TT
>:
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;divert(-1)
include(`../m4/cf.m4')
define(`confDEF_USER_ID',''8:12'')
define(`confBIND_OPTS',`-DNSRCH -DEFNAMES')
# here you define your domain
define(`confDOMAIN_NAME',''pa.uky.edu'')
OSTYPE(`linux')
undefine(`UUCP_RELAY')
undefine(`BITNET_RELAY')
# there we send outgoing email
define(`SMART_HOST',`server1.pa.uky.edu')
# there we send mail to users my laptop does not know
define(`LUSER_RELAY',`server1.pa.uky.edu')
# again the domain, we want to be seen as
MASQUERADE_AS(pa.uky.edu)
FEATURE(allmasquerade)
FEATURE(nouucp)
FEATURE(nodns)
FEATURE(nocanonify)
FEATURE(redirect)
FEATURE(always_add_domain)
FEATURE(use_cw_file)
FEATURE(local_procmail)
MAILER(procmail)
MAILER(smtp)
HACK(check_mail3,`hash -a@JUNK /etc/mail/deny')
HACK(use_ip,`/etc/mail/ip_allow')
HACK(use_names,`/etc/mail/name_allow')
HACK(use_relayto,`/etc/mail/relay_allow')
HACK(check_rcpt4)
HACK(check_relay3)
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; This looks more complicated as it is. All it does is, that it redirectes
outbound mail to server1 (SMART_HOST) and also mail for local users
which are not known (LUSER_RELAY). That way, I can write email to my
colleques without using their full email address. More important: the
From line in my email points back to my MASQUARADE_AS domain and not
directly to my laptop. If this where not the case, email returned with
the <EM
>reply</EM
> button might not reach me. You must
restart <B
CLASS="command"
>sendmail</B
> for changes to take effect. Note:
this configuration is for Redhat 5.2 systems. You may have to change
some details.
</P
><P
>&#13; Now, all what is needed is to generate the <TT
CLASS="filename"
>/etc/sendmail.cf
</TT
>file <B
CLASS="command"
>m4 laptop.mc &#62;/etc/sendmail.cf</B
> and
to add all possible domain names my laptop should respond to in
<TT
CLASS="filename"
>/etc/sendmail.cw</TT
>:
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;# sendmail.cw - include all aliases for your machine here.
laptop
laptop.pa.uky.edu
128.17.18.30
guest1
guest1.somewhere.org
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; It is important to have all aliases in this file, otherwise
<B
CLASS="command"
>sendmail</B
> will not accept the mail (and will reply
<EM
>we don't relay</EM
> to the sender). Finally, you must
now test the setup by sending email, replying to mail for all possible
configurations. Any missconfiguration can result in loss of email.
</P
></DIV
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN4119"
></A
>15.3.1.3. Configuration for fetchmail on Laptop</H3
><P
>&#13; One method to get the email into your machine is through
<B
CLASS="command"
>fetchmail</B
>. Fetchmail periodically checks for new
email at one or more remote mail servers. I use the following fetchmail
configuration file (in my user home directory):
<TT
CLASS="filename"
>fetchmailrc</TT
>
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;set postmaster "myusername"
set daemon 900
poll pop.uky.edu with proto POP3
user "mypopusername" there with password "mypoppassword" is mylaptopusername here
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Fetchmail will just get the email and send it to
<B
CLASS="command"
>sendmail</B
> which will it deliver into your
<TT
CLASS="filename"
>/var/spool/mail/$USER</TT
> file.
</P
></DIV
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN4129"
></A
>15.3.1.4. Forward E-Mail to the Laptop</H3
><P
>&#13; On my work station I have the following <TT
CLASS="filename"
>.forward</TT
>
file:
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;me@pop.acount.edu,me@server1
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Here server1 is the machine where I keep my mailbox. All email is send
to the pop account to be picked up later by my laptop (using
<B
CLASS="command"
>fetchmail</B
>). However, when my laptop is connected via
ethernet, I want my email to go directly to the laptop, instead of pop:
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;me@laptop,me@server1
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; In both cases, a backup of my email is send to server1 (where I also can
read it, in case I cannot get my laptop). I keep/store all email on the
laptop.
</P
><P
>&#13; Switching is done by three script files and a crontab file (on the
workstation):
</P
><P
>&#13; <TT
CLASS="filename"
>forward_pop</TT
>
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;#!/bin/sh
echo "me@pop.acount.edu,me@server1" &#62; ${HOME}/.forward
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; <TT
CLASS="filename"
>forward_laptop</TT
>
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;#!/bin/sh
echo "ppe@laptop,ppe@server1" &#62; ${HOME}/.forward
crontab ${HOME}/mycrontab
${HOME}/utl/check_laptop
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; <TT
CLASS="filename"
>check_laptop</TT
>
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;#!/bin/sh
if /usr/sbin/ping -c 1 laptop &#62;/dev/null 2&#62;&#38;1 ; then
:
else
# redirect mail to pop
${HOME}/utl/forward_pop
sleep 10
if /usr/sbin/ping -c 1 laptop &#62;/dev/null 2&#62;&#38;1 ; then
# back to normal
${HOME}/utl/forward_laptop
else
# deactivate crontab check
/bin/crontab -l | grep -v check_laptop &#62;${HOME}/tmp/mycrontab.tmp
/bin/crontab ${HOME}/tmp/mycrontab.tmp
rm -f ${HOME}/tmp/mycrontab.tmp
fi
fi
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; <TT
CLASS="filename"
>mycrontab</TT
>
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;# mycrontab
0,10,20,30,40,50 * * * * ${HOME}/utl/check_laptop
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Each time I connect the laptop to the ethernet, I have to run
<B
CLASS="command"
>forward_laptop</B
>, and each time I disconnect I run
forward_pop. In case I forget to run <B
CLASS="command"
>forward_pop</B
>, the
crontab job runs it for me less then 10 minutes later. To do all that
automatically, I change the network script files on my laptop as
follows:
</P
><P
>&#13; <TT
CLASS="filename"
>/sbin/ifdown</TT
> (this script runs, whenever a network
device is stopped, new stuff between BEGIN and END)
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;...
fi
# BEGIN new stuff
# turn off forwarding email
mail ppe &#60;&#60;EOF
turning off forwarding email
device = ${DEVICE}
hostname = `hostname`
EOF
if [ "${DEVICE}" = "eth0" -a "`hostname`"
= "laptop" ]; then
su -lc "ssh -l myusername server1
utl/forward_pop" myusername &#62;&#38; /dev/null
fi
# END new stuff
ifconfig ${DEVICE} down
exec /etc/sysconfig/network-scripts/ifdown-post $CONFIG
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Note, that the script checks for the value of hostname. In case, I am
connected to a foreign ethernet, my hostname and ip-address will be
something else, e.g. guest1.
</P
><P
>&#13; <TT
CLASS="filename"
>/etc/sysconfig/network-scripts/ifup-post</TT
> (this
script is run, whenever a network device is started)
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;# Notify programs that have requested notification
do_netreport
# BEGIN new stuff
# check for email -- I'm using fetchmail for this
if [ "${DEVICE}" = "eth0" -o "${DEVICE}"
= "ppp0" ]; then
su -lc fetchmail myusername &#62;&#38; /dev/null &#38;
fi
# set clock if connected to ethernet, redirect email
if [ "${DEVICE}" = "eth0" -a "`hostname`" = "zaphod" ]; then
( rdate -s server1 ; hwclock --systohc --utc ) &#62;&#38; /dev/null &#38;
# forward email
su -lc "ssh -l myusername gradj utl/forward_laptop" myusername &#62;&#38; /dev/null &#38;
fi
# END new stuff
exit 0
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
></DIV
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN4169"
></A
>15.3.1.5. Processing Incoming E-Mail with procmail</H3
><P
>&#13; This step is completely optional. The above described sendmail
configuration calls <B
CLASS="command"
>procmail</B
> for each received email,
but you could have called <B
CLASS="command"
>procmail</B
> using the
<B
CLASS="command"
>.forward</B
> file (see the procmail man page). Procmail
is a handy tool to block spam and to sort incoming email.
</P
><P
>&#13; You need to setup a <B
CLASS="command"
>.procmailrc</B
> file to use
<B
CLASS="command"
>procmail</B
>. See the man page for procmail, procmailrc,
and procmailex (examples). My setup demonstrates, how to ignore certain
email messages and split email-collections (digest) into pieces:
</P
><P
>&#13;
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;# -- mail filtering -- procmail is called by sendmail --
PATH=/bin:/usr/bin
MAILDIR=$HOME/Mail
LOGFILE=$MAILDIR/from
# keep in mind:
# use ":0:" when writing to a file
# use ":0" when writing to a device, e.g. /dev/null, or send email
# - make a backup of *all* incoming mail, but ignore mail tagged below -
:0 c:
*! ^Sissa-Repro
backup
# - keep only last 50 messages
:0 ic
| cd backup &#38;&#38; rm -f dummy `ls -t msg.* | sed -e 1,50d`
# - delete email coming through the 'postdocs' email list, when
# it is not of any interest
:0
* ^From.*postdocs
* ^From.*Ernst Richter /dev/null :0
* ^From.*postdocs
* ^Subject.*card charge
/dev/null
# Split mailing list from the sissa preprint server into individual emails
# - this is quite complicated :( I can flip through the list much
# faster and ignore preprints which have uninteresting titles. Instead of
# having to browse through the whole list, my mailer will just present a
# list of papers.
# 1. split it in individual messages
:0
* ^From no-reply@xxx.lanl.gov
| formail +1 -de -A "Sissa-Repro: true" -s procmail
# 2. reformat messages a bit
# 2.1. extract 'Title:' from email-Body and add to email-header
as 'Subject:'
:0 b
* ^Sissa-Repro
*! ^Subject
TITLE=| formail -xTitle:
:0 a
|formail -A "Subject: $TITLE " -s procmail
# 2.2. store in my incoming sissa-email folder. Here, we could
# also reject (and thereafter delete) uninteresting 'Subjects'
# we could also mark more interesting subjects as urgend or send a copy
# to regular mail box.
:0:
* ^Sissa-Repro
* ^Subject
*! ^replaced with
sissa
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; By the way, there is a <B
CLASS="command"
>tk</B
> GUI tool to configure
<B
CLASS="command"
>procmail</B
> (I think it is called
<B
CLASS="command"
>dotfiles</B
>).
</P
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN4184"
></A
>15.3.2. Email with UUCP</H2
><P
>&#13; Another possible solution for Email is to use UUCP. This software was
made for disconnected machines, and is by far the easiest solution if
you have several users on your laptop (we are talking about
<SPAN
CLASS="acronym"
>UNIX</SPAN
>, remember?), each with his/her own account.
</P
><P
>&#13; Unlike what most people think, UUCP does not need a serial
connection: it works fine over TCP/IP, so your UUCP partner can be
any machine on the Internet, if it is reachable from your network
attachment point. Here is the UUCP <TT
CLASS="filename"
>sys</TT
> for a
typical laptop:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;system mylaptop
time any
chat "" \d\d\r\c ogin: \d\L word: \P
address uucp.mypartner.org
port TCP
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN4191"
></A
>15.3.3. MailSync</H2
><P
>&#13; <A
HREF="http://mailsync.sourceforge.net/"
TARGET="_top"
>Mailsync</A
>
is a way of synchronizing a collection of mailboxes. The
algorithm is a 3-way diff. Two mailboxes are simultaneously compared to
a record of the state of both mailboxes at last sync. New messages and
message deletions are propagated between the two mailboxes. Mailsync
can synchronize local mailbox files in many formats and remote
mailboxes over IMAP, POP, and IMAPS.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="mobile-guide-p5c1s2-configuration-tools.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="mobile-guide-p5c1s3-data-transport.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Configuration Tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="mobile-guide-p5c1-different-environments.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Data Transport Between Different Machines (Synchronization)</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>