home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Enter 1999 June / enter_06_1999.iso / doc / HOWTO / mini / Mail-Queue < prev    next >
Text File  |  1998-10-14  |  14KB  |  463 lines

  1.   Linux Mail-Queue mini-HOWTO
  2.   Leif Erlingsson, leif@lege.com, Jan P Tietze, jpti¡
  3.   etze@mail.hh.provi.de
  4.   v2.02, 3 September 1997, sendmail 8.8.7
  5.  
  6.   Queue Remote Mail + Deliver Local Mail The Configuration Changes Nec¡
  7.   cessary to Make Sendmail Deliver Local Mail ***Now*** While Stashing
  8.   Remote Mail in The Queue Until "I Say So".
  9.   ______________________________________________________________________
  10.  
  11.   Table of Contents
  12.  
  13.  
  14.   1. Introduction
  15.  
  16.   2. NON dial-on-demand solutions PART
  17.  
  18.      2.1 Starting sendmail
  19.      2.2 Configuring sendmail
  20.         2.2.1 Configuring sendmail.cf directly, for trivial configurations
  21.         2.2.2 Configuring sendmail.cf using m4 source
  22.      2.3 Menu support suggestions
  23.  
  24.   3. Dial-on-demand solutions PART
  25.  
  26.      3.1 Configuring sendmail.cf
  27.         3.1.1 Configuring sendmail.cf directly, for trivial configurations
  28.         3.1.2 Configuring sendmail.cf using the m4 source.
  29.      3.2 Adding dial delay
  30.         3.2.1 Configuring sendmail.cf directly
  31.         3.2.2 Configuring sendmail.cf using m4 source
  32.  
  33.   4. Delivering e-mail
  34.  
  35.      4.1 How to have e-mail delivered at special times.
  36.  
  37.  
  38.   ______________________________________________________________________
  39.  
  40.   1.  Introduction
  41.  
  42.   The document is written by two authors. The NON dial-on-demand
  43.   solutions part (oldest part) is written by Leif Erlingsson
  44.   <leif@lege.com>, and the newer dial-on-demand solutions part is
  45.   written by Jan P Tietze <jptietze@mail.hh.provi.de>.
  46.  
  47.  
  48.  
  49.   2.  NON dial-on-demand solutions PART
  50.  
  51.   Written by Leif Erlingsson <leif@lege.com>.
  52.  
  53.   The original version of this part contained a lot of unnecessary
  54.   stuff.  This is all it takes, really...
  55.  
  56.  
  57.   2.1.  Starting sendmail
  58.  
  59.   Slackware et al:        /etc/rc.d/rc.M:
  60.  
  61.  
  62.  
  63.        echo "Starting sendmail daemon (/usr/sbin/sendmail -bd -os) [queue only mode]..."
  64.        /usr/sbin/sendmail -bd -os      # NOT "-bd -q 15m", the "standard" flags!
  65.  
  66.  
  67.   RedHat et al:           /etc/rc.d/init.d/sendmail.init:
  68.  
  69.  
  70.  
  71.        echo -n "Starting sendmail: [queue only mode]"
  72.        daemon sendmail -bd -os         # NOT daemon sendmail -bd -q1h
  73.  
  74.  
  75.  
  76.  
  77.  
  78.   The -os is not really essential, all it does is this:
  79.  
  80.  
  81.  
  82.        SuperSafe [s] Be super-safe when running things, i.e.,
  83.                always instantiate the queue file,  even  if
  84.                you are going to attempt immediate delivery.
  85.                Sendmail always instantiates the queue  file
  86.                before  returning  control  the client under
  87.                any  circumstances.   This   should   really
  88.                always be set.
  89.  
  90.  
  91.  
  92.  
  93.  
  94.   This should already be configured in the default sendmail.cf anyway.
  95.  
  96.  
  97.   2.2.  Configuring sendmail
  98.  
  99.   Serious sendmail users use the m4 source for this. I recommend this
  100.   solution if you ever plan on upgrading sendmail and also make anything
  101.   but trivial changes to sendmail.cf.
  102.  
  103.   If you never intend to fix sendmail so envelope return headers et al
  104.   works even though you might be on dynamic dial in IP or something,
  105.   then you may not need to get the m4 source.
  106.  
  107.  
  108.   2.2.1.  Configuring sendmail.cf directly, for trivial configurations
  109.  
  110.   This way of doing things is extremeley version dependent vs.
  111.   sendmail.cf versions. The following solution is *only* valid for
  112.   sendmail-8.8.x.
  113.  
  114.   Edit /etc/sendmail.cf:
  115.  
  116.  
  117.  
  118.        # avoid connecting to "expensive" mailers on initial submission?
  119.        O HoldExpensive=True
  120.  
  121.  
  122.  
  123.  
  124.   ... later ...
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.   #####  @(#)smtp.m4      8.33 (Berkeley) 7/9/96  #####
  134.  
  135.   Msmtp,          P=[IPC], F=mDFMuXe, S=11/31, R=21, E=\r\n, L=990,
  136.                   T=DNS/RFC822/SMTP,
  137.                   A=IPC $h
  138.   Mesmtp,         P=[IPC], F=mDFMuXae, S=11/31, R=21, E=\r\n, L=990,
  139.                   T=DNS/RFC822/SMTP,
  140.                   A=IPC $h
  141.   Msmtp8,         P=[IPC], F=mDFMuX8e, S=11/31, R=21, E=\r\n, L=990,
  142.                   T=DNS/RFC822/SMTP,
  143.                   A=IPC $h
  144.   Mrelay,         P=[IPC], F=mDFMuXa8e, S=11/31, R=61, E=\r\n, L=2040,
  145.                   T=DNS/RFC822/SMTP,
  146.                   A=IPC $h
  147.  
  148.  
  149.  
  150.  
  151.  
  152.   The important flag above is ``e''. Don't fuss if the other flags look
  153.   different in your file. Keep your flags as-is, only add ``e'' to your
  154.   flags according to the above examples, unless it's there already.
  155.   ``e'' marks the mailers as ``expensive''.
  156.  
  157.  
  158.   2.2.2.  Configuring sendmail.cf using m4 source
  159.  
  160.   In the following I will, for simplicity, assume that the sendmail
  161.   version is 8.8.7. If you have a different version, replace 8.8.7 with
  162.   that version number below! Also, the instructions will not work for
  163.   older versions of sendmail. Get the latest sendmail!
  164.  
  165.  
  166.   Download the sendmail source.  Try ``http://WWW.Sendmail.ORG'' or
  167.   possibly ``ftp.sendmail.org''.
  168.  
  169.  
  170.   I also recommend that you obtain my patch for allowing envelope sender
  171.   reverse aliasing and other nice stuff to really make you take control
  172.   over your mail environment.
  173.  
  174.   Write to ``Sendmail Patch <sendmail@lege.com>'', Subject:
  175.   ``sendmail-8.8.7'', if 8.8.7 is your sendmail version.
  176.  
  177.   They are also available from ``http://www.lege.com'', as is the sgml
  178.   source of this mini-HOWTO!
  179.  
  180.   You don't have to get my patches in order to get ``Queue Remote Mail +
  181.   Deliver Local Mail'' to work. My patches solve other things. But I
  182.   just thought this would be a nice place to mention them, as many Linux
  183.   users will find them extremely useful.  (They will even give you
  184.   properly working virtual domains, if you like. The virtual domains
  185.   don't have to be ``local''. They will give you ``xaliases'', or in
  186.   other words ``reverse aliasing''.)
  187.  
  188.   Unpack the sendmail source. You may get /usr/src/sendmail-8.8.7/.  cd
  189.   /usr/src/sendmail-8.8.7/cf
  190.  
  191.   Now overlay my patch, if you want it, otherwise skip this step: If you
  192.   don't want to use procmail as Local Delivery Agent, save away your
  193.   /usr/src/sendmail-8.8.7/cf/ostype/linux.m4 before doing this...  Save
  194.   my patch to ``/tmp/sendmail-8.8.7-cf-cpio-idcmu.gz'', then...
  195.  
  196.  
  197.  
  198.  
  199.   cd /usr/src/sendmail-8.8.7/cf
  200.   gzip -dc < /tmp/sendmail-8.8.7-cf-cpio-idcmu.gz | cpio -idcmu
  201.  
  202.  
  203.  
  204.  
  205.   If you didn't want to use procmail, write back the saved copy of
  206.   /usr/src/sendmail-8.8.7/cf/ostype/linux.m4 again.
  207.  
  208.   And regardless of if you applied my patch or not, you must make sure
  209.   these lines or very similar ones are added to
  210.   /usr/src/sendmail-8.8.7/cf/cf/yourhostname.smtp.mc (but if you applied
  211.   my patch you may want to investigate filenames containing the word
  212.   ``elijah'', under /usr/src/sendmail-8.8.7/cf):
  213.  
  214.  
  215.  
  216.        dnl # Defer Delivery to "expensive" mailers until next time the
  217.        dnl # queue is processed using "O HoldExpensive=True" and make
  218.        dnl # sure smtp mailers are "expensive".
  219.        dnl # (See original "sendmail" book Chapter 30: Options,
  220.        dnl # "Oc - Don't connect to expensive mailers", or
  221.        dnl # 2nd Edition "sendmail" book Chapter 34.8.29,
  222.        dnl # "HoldExpensive (c), Queue for expensive mailers".)
  223.        dnl #                           / Leif Erlingsson <leif@lege.com>
  224.        define(`confCON_EXPENSIVE', `True')
  225.        define(SMTP_MAILER_FLAGS, e)
  226.        MAILER(local)dnl
  227.        MAILER(smtp)dnl
  228.  
  229.  
  230.  
  231.  
  232.  
  233.   2.3.  Menu support suggestions
  234.  
  235.   The 1.x versions of this document contained Menu support suggestions
  236.   for /var/X11R6/lib/fvwm/system.fvwmrc. I have dropped those in the
  237.   current version, but they are available on request:
  238.  
  239.  
  240.   Write to ``Menu support suggestions <fvwmrc@lege.com>'', Subject:
  241.   ``Menu support suggestions''
  242.  
  243.  
  244.  
  245.   3.  Dial-on-demand solutions PART
  246.  
  247.   Written by Jan P Tietze <jptietze@mail.hh.provi.de>.
  248.  
  249.   Many Linux users access the Internet through a dialup line, and many
  250.   have decided to implement dial-on-demand facilities on their system.
  251.   That is, whenever an IP packet of some sort has to leave the local
  252.   network or the local host, the link to an Internet Service Provider
  253.   (ISP) will automatically be established. The link will be dropped
  254.   after some period of time that no packet has travelled across.
  255.  
  256.   Although this is very comfortable and cost effective, there is one
  257.   special case in which this is neither comfortable (as the time to
  258.   bring up a "traditional" modem dialup is very noticeable) nor cost
  259.   effective, and this is sending e-mail. E-Mail is commonly sent by
  260.   SMTP, either delivered by your own system or through a SMTP host on
  261.   the Internet that usually resides in your ISP's network.
  262.  
  263.   With dialup lines, every time you send a message the link will have to
  264.   be brought up. This is quite okay if you send only one message, but if
  265.   you happen to create and send multiple messages, bringing up the line
  266.   more than once can be tedious and cost ineffective. Also, if your ISP
  267.   imposes limits as to what times you are allowed to login, this would
  268.   also restrict you to postpone messages at certain times of the day,
  269.   and you would have to manually send them later.
  270.  
  271.   Section 1 of this document will solve the situation, however in
  272.   situations where an external DNS lookup would cause the link up, the
  273.   link will still be established even if e-mail is just being queued.
  274.   The reason is that sendmail wishes to "canonify" host names.
  275.  
  276.   The solution to this problem is twofold: First, we'll have to
  277.   moderately change sendmail.cf. And then we have to define the process
  278.   of actual mail delivery. Personally, I prefer to have cron do the job
  279.   for me and describe the necessary changes below.
  280.  
  281.  
  282.   3.1.  Configuring sendmail.cf
  283.  
  284.   For the reasons stated in [1.2], I recommend modifying the m4 sources
  285.   instead of editing sendmail.cf directly. It will actually save you a
  286.   lot of hassle and make configuration changes more verbose.
  287.  
  288.   First, perform all the changes described in the first part of this
  289.   document. Then go through the dial-on-demand specific stuff.
  290.  
  291.  
  292.   3.1.1.  Configuring sendmail.cf directly, for trivial configurations
  293.  
  294.   Configuring directly is highly impractical and anything but verbose,
  295.   but obviously, this is your decision.
  296.  
  297.   Close to very bottom of your sendmail.cf should be a line that reads:
  298.  
  299.  
  300.  
  301.        R$* < @ $* $~P > $*             $: $1 < @ $[ $2 $3 $] > $4
  302.  
  303.  
  304.  
  305.  
  306.   Precede that line with a "#" so that it reads
  307.  
  308.  
  309.  
  310.        #R$* < @ $* $~P > $*            $: $1 < @ $[ $2 $3 $] > $4
  311.  
  312.  
  313.  
  314.  
  315.  
  316.   3.1.2.  Configuring sendmail.cf using the m4 source.
  317.  
  318.   Add the following line to
  319.   /usr/src/sendmail-8.8.7/cf/cf/yourhostname.smtp.mc:
  320.  
  321.  
  322.  
  323.        FEATURE(nocanonify)dnl
  324.  
  325.  
  326.  
  327.  
  328.   Your final sendmail.cf can then be built by issuing the following
  329.   commands. Remember to always back up your old /etc/sendmail.cf before
  330.   installing the new one:
  331.        cp /etc/sendmail.cf /etc/sendmail.cf.bak
  332.        cd /usr/src/sendmail-8.8.7/cf/cf
  333.        m4 yourhostname.smtp.mc > /etc/sendmail.cf
  334.  
  335.  
  336.  
  337.  
  338.  
  339.   3.2.  Adding dial delay
  340.  
  341.   It is oftentimes useful, especially when using modem lines, to have a
  342.   dial delay installed. This means that if sendmail tries to initiate a
  343.   connection in an attempt to send an e-mail (and this causes the line
  344.   to go up) but the link actually takes more time to get established
  345.   than what sendmail thinks should be a reasonable timeout, sendmail
  346.   will simply wait some seconds and then retry.
  347.  
  348.  
  349.   3.2.1.  Configuring sendmail.cf directly
  350.  
  351.   Somewhere in your sendmail.cf could be a line that would read:
  352.  
  353.  
  354.  
  355.        #O DialDelay=10s
  356.  
  357.  
  358.  
  359.  
  360.   (or very similar). Delete the ``#''. If there's no ``#'' at the
  361.   beginning of the line, things should be considered okay (it just means
  362.   this had already been enabled before).
  363.  
  364.   If there is no such line in your sendmail.cf, add one (it is a wise
  365.   thing to do to add this in the "options" part of the file):
  366.  
  367.  
  368.  
  369.        O DialDelay=10s
  370.  
  371.  
  372.  
  373.  
  374.   Now change the ``10s'' part to the number of seconds you deem
  375.   suitable.
  376.  
  377.  
  378.   3.2.2.  Configuring sendmail.cf using m4 source
  379.  
  380.   Add the following line to
  381.   /usr/src/sendmail-8.8.7/cf/cf/yourhostname.smtp.mc:
  382.  
  383.  
  384.  
  385.        define(`confDIAL_DELAY',`10s')
  386.  
  387.  
  388.  
  389.  
  390.   Now change the ``10s'' part to the number of seconds you deem
  391.   suitable.
  392.  
  393.   Your final sendmail.cf can then be built by issuing the following
  394.   commands. Remember to always back up your old /etc/sendmail.cf before
  395.   installing the new one:
  396.  
  397.        cp /etc/sendmail.cf /etc/sendmail.cf.bak
  398.        cd /usr/src/sendmail-8.8.7/cf/cf
  399.        m4 yourhostname.smtp.mc > /etc/sendmail.cf
  400.  
  401.  
  402.  
  403.  
  404.  
  405.   4.  Delivering e-mail
  406.  
  407.   E-Mail delivery can be invoked by issuing the command "sendmail -q".
  408.   For those who are interested in what sendmail actually does, "sendmail
  409.   -q -v" will give a more verbose version of the delivery process.
  410.  
  411.   It is very convenient to automate the process of e-mail delivery. A
  412.   tool commonly used for this process is cron.
  413.  
  414.  
  415.   4.1.  How to have e-mail delivered at special times.
  416.  
  417.   Edit your crontab:
  418.  
  419.  
  420.  
  421.        crontab -e
  422.  
  423.  
  424.  
  425.  
  426.   Add lines of the form:
  427.  
  428.  
  429.  
  430.        05 18-23,0-7    * * Mon,Tue,Wed,Thu,Fri /usr/sbin/sendmail -q
  431.        05 *            * * Sat,Sun             /usr/sbin/sendmail -q
  432.  
  433.  
  434.  
  435.  
  436.   Please refer to the crontab man page (available through "man 5 \
  437.   crontab") for further information. I think the format is pretty
  438.   obvious. The example crontab entries shown above send e-mail (if, and
  439.   only if, e-mail is available from the queue) 5 minutes after an hour
  440.   on weekdays, starting at 6:05 pm, and stopping at 7:05 am.  On
  441.   weekends, e-mail is delivered 5 minutes after an hour, starting at
  442.   12:05 pm on Saturday, and stopping 11:05 pm on Sunday.
  443.  
  444.   As a dial-on-demand user, it is sometimes desirable to have your
  445.   system collect your e-mail via the POP3 protocol at certain times of
  446.   the day. You could therefore add an entry similar to the following to
  447.   your crontab:
  448.  
  449.  
  450.  
  451.        0 21            * * * popclient -3 -u <your pop3 user name
  452.        goes here> -p <put your password here> -o /var/spool/mail/<the user
  453.        on your system that should receive the collected e-mail>
  454.        <mailhost.somedomain.com>
  455.  
  456.  
  457.  
  458.  
  459.   Of course, this should all go on a single line.
  460.  
  461.   Then, save the file and leave the editor. The crontab should now be
  462.   installed.
  463.