个人工具

UbuntuHelp:DialupEmailHowto

来自Ubuntu中文

跳转至: 导航, 搜索

<<Include(Tag/Unsupported)>>

How To Set Up Email on a Dialup Connection

This sets up local handling of mail so a dialup user can read and queue mail while on or off line. This information assumes a standard Ubuntu "warty" setup. (Here's the scenario -- I set up Ubuntu on a PC for my Mother-in-law, but she has only one phone line and no broadband. I didn't want to have to explain the error messages she would see if she attemtped to read or compose email when the machine is not online. All the "hooks" exist to automatically retrieve and deliver the email over a ppp connection, but they must be set up.)

Contents

  • 0) Before you start -- Information you need
  • 1) Set up modem (ppp and modemlights)
  • 2) Set up incoming mail (fetchmail)
  • 3) Set up outgoing mail (postfix)
  • 4) Set the system clock when online (ntpdate)
  • 5) Configure email client (Evolution)
  • Finishing touches
  • Smooth fonts in Warty
  • Postfix documentation
  • Comments

0) Before you start -- Information you need

  • The phone number & other modem settings for your Internet Server Provider (ISP)
  • Your username and password at your ISP
  • Your username and password at your email provider (if different)
  • Your email provider's SMTP server name
  • Your email provider's POP or IMAP server name

In the examples here, the email provider is fastmail.fm, whose smtp server is smtp.messagingengine.com and whose pop/imap server is mail.messagingengine.com. Fastmail is an actual email ISP whose SMTP and IMAP servers are available to fee-paying subscribers. Please substitute these examples with your own information...

1) Set up modem (ppp and modemlights)

see [DialupModemHowto] Test to make sure the system seems to connect properly -- open a web page while connected, etc.

2) Set up incoming mail (fetchmail)

Fetchmail is already installed in Warty, but

  • some scripts need modification to respect the ppp connection, *and*
  • there is no configuration file, so fetchmail will not start.

Modify the script that runs when the modem connects which is located at /etc/ppp/ip-up.d/fetchmail Change the try-restart command to start, so that one line now says:

     /etc/init.d/fetchmail start

Also modify the script that runs when the modem disconnects which is located at /etc/ppp/ip-down.d/fetchmail Comment out the exit 0 line in this fetchmail script so it now says:

     #exit 0

Create a fetchmail config file in /etc/fetchmailrc . (Pay special attention to the placement of commas, semicolons and colons)

     #!/etc/fetchmailrc
     #
     # global options
     # set logging to syslog
     set syslog
     # set to run as daemon with poll interval (seconds)
     set daemon 240
     #
     poll mail.messagingengine.com:
        # server options
        with nodns,
        with protocol imap,
        # user options
        user remote_account_name there, is, local_account_name here,
        # with stripcr,
        # with keep,
        with password my_secret;

Comments regarding the script above:

  • Remember to replace *mail.messagingengine.com* with your email server name.
  • This script uses *imap* but *pop3* also works with this provider.
  • Substitute your email account name (to the left of the @ sign) for *remote_account_name*.
  • Substitute your ubuntu login name for *local_account_name*.
  • The *stripcr* command is commented out because I don't think I need it.
  • To leave the messages on the mail server, uncomment the *with keep* line. (Fetchmail will only retrieve a message once, but with the *keep* command the original will stay on the server after it's retrieved.)

Fetchmail insists on secure permissions for the fetchmail configuration file, so set them securely --

     # sudo chmod 0600 /etc/fetchmailrc

3) Set Up outgoing mail (postfix)

The postfix mail server comes installed on Warty, but by default it only delivers system warnings and other messages to the first user on the system. This procedure assumes your ISP requires TLS authentication (which verifies your identity to show you're not a spammer trying to take over their SMTP server).

     # sudo dpkg-reconfigure postfix

(Many of the following responses are the system defaults)

  • Choose: satellite system
  • Mail name: localhost.localdomain
  • SMTP Relay host: smtp.messagingengine.com
  • Other destinations to accept mail for: localhost.localdomain, localhost
  • Force synchronous updates on mail queue: Yes
  • Local networks: 127.0.0.0/8
  • Use procmail for local delivery: No
  • Mailbox size limit: 0
  • Local address extension character: +

Edit the postfix config which is located at /etc/postfix/main.cf Scroll down to the end of the file and add the following lines:

     # lines below added by >you< on >date<
     # See http://www.michael-prokop.at/postfix/

     #Most ISPs block port 25 these days; most ISPs offer port 587 as an alternate.  (Some support ports other than the MSP port, such as 26, 2525, etc.)
     # Also, the square brackets are supposed to be there-do NOT leave them out.
     relayhost = [mail.messagingengine.com]:587

     # TLS authentication
     smtp_use_tls = yes
     smtp_sasl_auth_enable = yes
     smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
     smtp_sasl_security_options = noanonymous

     # Settings for dialup
     defer_transports = smtp
     disable_dns_lookups = yes

     # Address envelopes to avoid bounces
     masquerade_domains = /etc/mailname

(Lines beginning with "#" are comments.) Add authentication information to config file located here /etc/postfix/smtp_auth (one line only)

     mail.messagingengine.com my_email_address:my_secret_password

Put return address host into mailname file located at /etc/mailname

     fastmail.fm

Change the line to the part of your email address *after* the @ sign. Now, add the updated info to postfix database & restart postfix. (Run this procedure any time you must make changes to the smtp_auth settings; it converts the contents of /etc/postfix/smtp_auth into /etc/postfix/smtp_auth.db, a format postfix expects.)

     # sudo postmap /etc/postfix/smtp_auth
     # sudo /etc/init.d/postfix restart

Test your postfix setup from the command line by sending a message to yourself:

     # echo "postfix works" | mail [email protected]

Problems? Look in the outgoing mail queue:

     # mailq

(The message should be gone already if you're online.) If you find a problem, and need to edit the files in /etc/postfix, run the postmap command and restart postfix like described above. If you see undeliverable junk in the deferred email queue:

     # sudo postsuper -d ALL deferred

This command removes the messages from the "deferred" queue so the system won't keep trying to deliver them. There are many other postfix commands; see the links in the `Postfix Documentation`_ section.

4) Set the system clock when online (ntpdate)

Create a script that calls ntpdate when the modem connects:

     # sudo nano /etc/ppp/ip-up.d/2ntpdate
     #!/bin/sh
     # update time when online
     /etc/init.d/ntpdate restart

Set permissions on the script you just wrote

     # sudo chmod 755 /etc/ppp/ip-up.d/2ntpdate

5) Configure Email Client (Evolution)

Launch Evolution and set it to look for mail in all the right places. Tools -- > Settings... Click the "Add" button to create a new account

  • Receiving Mail: Local Delivery
  • Receiving Options: check for new mail every minute or two
  • Sending Mail: Server Type: sendmail

Finishing touches

Here are some extras to ensure things operate smoothly and easily...

  • Make sure the machine starts and stops without strangeness (it should power down properly, for example).
  • Set GDM to log in automatically if desired
  • Adjust Gnome screen resolution, colors and font sizes for user's eyes as necessary
  • Make fonts smooth using Smooth fonts in Warty
  • Make GRUB menu usable for another OS if desired

Smooth fonts in Warty

Create the ./fonts.conf file in the home directory to make the fonts look smooth on the screen. If you already have this file, add the parts from <match target="font"> to </match>.

     nano ~/.fonts.conf
     <?xml version="1.0"?>
     <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
     <fontconfig>
       <match target="font">
         <edit name="autohint" mode="assign">
           <bool>true</bool>
         </edit>
       </match>
     </fontconfig>

Postfix documentation

There's lots of information for using postfix on a dialup connection at Red Hat, though it turns out the Postfix site has lots of information, too. The Debian default package settings are configured a bit differently from Red Hat's, making their advice potentially confusing. Here are links to the documentation I have found most helpful:

Comments

TommyTrussell commented on Wed Dec 15 16:58:11 +0000 2004 Subject: Entire original /etc/postfix/main.cf Message-ID: <20041215165811+0000@https://www.ubuntulinux.org> that he would post his entire /etc/postfix/main.cf file after editing it as described in the original instructions (from November 30, 2004). What is now below is an edited version of his second version; the edit should work/resolve the issue he had, and serve as a better example. (See the wiki history if you're interested in the previous versions.) Revised 12/16/2004 by TommyTrussell and Aug 2007 by MrElvey

     # See /usr/share/postfix/main.cf.dist for a commented, more complete version
     
     # For better performance, chattr -S -R /var/spool/postfix, and use a
     # journaled filesystem to achieve the same results as chattr +S gives.
     
     smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
     biff = no
     
     # appending .domain is the MUA's job.
     append_dot_mydomain = no
     
     # Uncomment the next line to generate "delayed mail" warnings
     #delay_warning_time = 4h
     
     # Uncomment the next line to use procmail for delivery
     #mailbox_command = procmail -a "$EXTENSION"
     
     myhostname = localhost.localdomain
     alias_maps = hash:/etc/aliases
     alias_database = hash:/etc/aliases
     myorigin = /etc/mailname
     mydestination = localhost.localdomain, localhost



     # See http://www.michael-prokop.at/postfix/

     #Most ISPs block port 25 these days; most ISPs offer port 587 as an alternate.  (Some support ports other than the MSP port, such as 26, 2525, etc.)
     # Also, the square brackets are supposed to be there-do NOT leave them out.
     relayhost = [mail.messagingengine.com]:587
     
     mynetworks = 127.0.0.0/8
     mailbox_command =
     mailbox_size_limit = 0
     recipient_delimiter = +

     # lines below added by twt 12/16/2004

     # TLS authentication
     smtp_use_tls = yes
     smtp_sasl_auth_enable = yes
     smtp_sasl_password_maps = hash:/etc/postfix/smtp_auth
     smtp_sasl_security_options = noanonymous

     # Settings for dialup
     defer_transports = smtp
     disable_dns_lookups = yes

     # Address envelopes to avoid bounces
     masquerade_domains = /etc/mailname

From TommyTrussell never could get this configuration to work reliably... but with the square brackets now above; perhaps he would... Take care to not copy/paste the spaces in front of each line, as those seem to mean to Postfix "merge this with the previous line" (just like in good ole RFC822, imagine that). Other than that, the Postfix part works nicely even for me on Gutsy. Thanks! -- Era