Как настроить fetchmail опция smtpname на ubuntu

Обновлено: 06.07.2024

How to use Postfix and Fetchmail to access a single Gmail account using an old-fashioned client such as mutt or Emacs GNUS.

This setup is intended to be as simple and as close to a standard Ubuntu configuration as possible. This setup does not verify the Gmail SMTP server certificate.

Not For Beginners

  • How to install packages
  • How to edit text configuration files.
  • Terms like POP3, SMTP and SSL.

References

You will need the postfix and fetchmail packages. See InstallingSoftware for more on installing packages. Postfix will work on Ubuntu as is from apt-get without any compilation necessary

A "mail delivery agent" is the back end used to store mails, which can be postfix. A "mail transfer agent" is a server talking SMTP : it receives mail via SMTP, and it can pass it on via SMTP. Postfix is a combination of MTA and MDA.

to send every mail through Google you also need to set option as

Another option is to use a transport map.

The easiest is to just use a mail client, and nothing inter-locuting, but we are not doing this by using postfix at all. Postfix may and can be used as a storage mail retrieval of fetchmail exclusively, and let the mail client perform the smtp encryption to google directly. So this is available as an alternative plan, when this one does work. It is very time-consuming, awkward, frustrating, and annoying.

  • /etc/postfix/main.cf
  • /etc/postfix/generic
  • /etc/postfix/generic.db
  • /etc/postfix/passwd
  • /etc/postfix/passwd.db

You will need root access to create and edit these files; see RootSudo for more on gaining root access.

Stop Postfix

It's not necessary to do so, but if you wish to stop Postfix while configuring, run (as root)

/etc/postfix/main.cf

When you install Postfix you will be prompted to make configurative choices. You can choose "No configuration"; in this case no configuration file will be created, and you can use the contents below. The configuration choices used to create it are listed in the Appendix.

This is the Postfix configuration file /etc/postfix/main.cf:

An explanation of each non-standard line (following the comment "non debconf entries start here") is given in the Appendix.

/etc/postfix/generic and /etc/postfix/generic.db

The /etc/postfix/generic is a plain text file, and should look as follows:

/etc/postfix/generic.db is generated from this using the postmap command:

/etc/postfix/sasl/passwd and /etc/postfix/sasl/passwd.db

The passwd file contains your Gmail password. Like /etc/postfix/generic file discussed above, it is a plain text file; it should look as follows:

To create passwd.db, and set ownership and permissions appropriately, run the following commands:

Start or reload Postfix

If you previously stopped Postfix, restart it with

If you didn't stop Postfix, force it to reload its configuration with

Testing

One possibly inconvenient feature of sendmail -bv is that the result is mailed to the user who ran the command; thus, if mail is utterly misconfigured, you will never receive the result. If you suspect this is the case, you can check /var/log/mail.log to see what went wrong, or you can type mail within the same account as the sender.

To check that basic delivery works, run the following command as a normal user (replacing "jane", as elsewhere, with your username):

You should receive a mail starting with:

If this didn't work, make sure that Postfix is running.

To check that Postfix can successfully connect to gmail, run

You should receive a mail starting with:

Potential problems with this are discussed in the following section.

Potential Postfix problems

Cannot find password

If you get an error message like this:

then Postfix cannot figure out what password to send gmail; make sure that the smtp_sasl_password_maps entry in /etc/postfix/main.cf is correct, that /etc/postfix/sasl/passwd is correct, and that you've created /etc/postfix/sasl/passwd.db.

No mechanism available

If you get an error message like this:

you have probably forgotten the smtp_sasl_security_options line in /etc/postfix/main.cf.

The setup presented here configures the system-wide fetchmail service, which is by default always running; for this use /etc/fetchmailrc is the configuration file. If you want to run fetchmail as your normal user you should use

/.fetchmailrc; that case is not further discussed here.

Unlike the Postfix setup above, the fetchmail configuration presented here will verify the Gmail POP3 server's certificate.

Stop the fetchmail service

To stop fetchmail while configuring it, run

/etc/fetchmail.rc

The file /etc/fetchmailrc should look as follows:

A detailed explanation is given in the appendix, though fetchmail's configuration language hopefully makes it clear.

Since this file contains your Gmail password, you may wish to give it restrictive read permission:

Testing

To test your configuration, run fetchmail as below; this should be run as root, since it reads /etc/fetchmailrc.

Take a look at /var/log/mail.log (e.g., using less /var/log/mail.log) to see that the connection was successful.

Restart fetchmail

Once your configuration is working, you can restart fetchmail with

Debconf choices for main.cf above

with the following selections:

Explanation of /etc/postfix/main.cf

Enable SMTP authentication.

Where the SMTP authentication data is to be found.

Where the generic mapping data is to be found.

Address and port number for SMTP connections. Putting the hostname in square brackets means it is interpreted as a hostname, rather than a mail name (as I understand it, Postfix uses "normal" DNS records rather than MX records when square brackets are used).

Explanation of /etc/fetchmailrc

Run man fetchmail for details. Fetchmail's configuration language has the interesting property of ignoring some words (like "with") and punctuation (like the comma and semicolon).

Log messages to syslog; fetchmail messages will appear in /var/log/mail.log.

Check for mail every 240 seconds.

Each account entry starts with keyword "poll", followed by the server hostname.

This is probably unnecessary.

Login to the POP3 server with username "jane.doe@gmail.com"; deliver mail to local user "jane".

The POP3 password is "doeadeer".

Use SSL in communicating to the POP3 server, and verify that the certificate is valid. fetchmail uses the certificates provided by the ca-certificates packages for this.

Verifying the Gmail SMTP server certificate

The configuration above does not verify the certificate of the Gmail SMTP server. This would be very easy to do but for Bug 118963

If you need this verification, you can either read reference 2 above, which shows you how to download and install the certificate yourself, or you can do something like this:

Then, in main.cf, change the smtp_tls_security_level line and add an smtp_tls_CApath line as follows:

This might need to be redone if you upgrade postfix (e.g., when upgrading Ubuntu).

If Nothing Is Working

If possible, check that you can access the Gmail SMTP and POP3 services with a client like Thunderbird; Google provide complete instructions for setting up Thunderbird here.

You can try port 465 instead of 587 for SMTP.

You can do a check that SMTP connections can be made using stunnel, as follows:

You should see something like this:

Terminate this connection with Ctrl-C.

You can also try testing the POP3 connection, though I had no success with this:

Note that you cannot use openssl's s_client to test the SMTP connection; Gmail's SMTP server requires the client to begin communications with HELO (or EHLO), while s_client jumps straight to STARTTLS.

Now you MUST MUST MUST alter the master.cf file as demonstrated in reference 2. If you do not you might experience looking at a server certificate error in your mailq.

Another, and THE MOST IMPORTANT, thing is that probably your $mydomain, $myhostname, and a load of other things are not concurring with register user accounts on your local computer. The solution is within /usr/share/postfix/main.cf.dist which is a commented, more complete version of a main.cf The clue lies in the fall_transport variable. This permits postfix to work far less rigidly on machines which have spoof domains established within /etc/hosts by the benefit til the operation of nntp servers like leafnode.

If you are still having problems with authorisation and certificate recognition, forget the above about the snakeoil certificate, and follow the most excellent instructions to make your own certificate at reference 7 This page is more useful than this whole venture by postfix itself. If it works it feels rewarding, but it can take one week of effort and worthwhile learning.

GmailPostfixFetchmail (последним исправлял пользователь k.dejong 2011-04-09 00:37:20)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Please note that these manual installation instructions should only be used on Ubuntu distributions, such as Ubuntu Gutsy Gibbon 7.10 server, the distribution the document was written for. If you install Scalix on an unsupported platform, this invalidates your ability to receive Scalix support. Also the usage of third party tools like fetchmail might not be supported. Thank you for your understanding and compliance.

This document might be inaccurate and under construction. Do not trust this document.

As Ubuntu 7.10 is an unsupported platform there is currently no manual describing the installation of fetchmail (a tool that can be used to retrieve and forward email) to be used in combination with Scalix. As I managed to get Scalix it up and running and I already documented and shared this with the community (here), I thought it would be useful to share my experiences regarding the fetchmail configuration as well.

So below you'll find a how-to that describes the installation and configuration of fetchmail to be used with Scalix on a Ubuntu 7.10 server.

Fetchmail is a mail-retrieval and forwarding utility that can fetch mail from remote mailservers (e.g. pop3 and imap) and forwards it to your local machine’s delivery system (Scalix in this case). The fetchmail utility can be run in a daemon mode to repeatedly poll one or more systems at a specified interval, and that's what this how-to will describe.

I used several sources of information on the web. I listed the ones I can remember at the end of the document under Sources.

Applicable Environments

These Installation instructions have been tested with

  • Scalix CE 11.3.0
  • Ubuntu 7.10 Server (Gutsy Gibbon)

They might not apply unmodified to any other version of Scalix or Ubuntu.

Install the fetchmail software

Fetchmail is Open Source Software available on the internet here. Under Ubuntu we have a package available that can be installed directly with apt-get. So install the fetchmail package:

Configure fetchmail

To make fetchmail run in daemon mode and have it poll for mail from several pop3 or imap servers frequently, you have to edit two configuration files: /etc/fetchmailrc and /etc/default/fetchmail.

In the file /etc/default/fetchmail you have to change the START_DAEMON directive from no into yes. After that the file should look like this:

This makes sure the fetchmail will be able start in daemon modus. It will also make sure that the fetchmail daemon will start automatically when the system starts.

The file /etc/fetchmailrc should be created as it does not exist yet. So use your favorite text editor and create a file that looks like this:


The directive set syslog; tells fetchmail to use the syslog system to log it's activities and possible errors.

The directive set daemon 90; tells fetchmail the interval to poll for new messages on the servers, in this example it is set to 90 seconds.

The directive set postmaster "my.email@mydomain.com"; provides fetchmail with an email address to send error messages and message that cannot be delivered to.

You may add as much servers a you like to the fetchmailrc file. They will all be polled for messages subsequently.

Start fetchmail and check the fetchmail configuration

To make sure your configuration is all right, start fetchmail. To do so, use this command:

Next, to check the configuration, have a look at the log file /var/log/mail.log. You can check it by using:

If there's something wrong, have a look at the exact error message and fix the problem. If everything is all right, then you're done: congratulations!

If you would like to fetch your email from your Gmail account into your Scalix instance have a look at this website:

The origin for this document was written by Max Wiertz. As a Scalix newbie, I invested a lot of work in getting Scalix together with fetchmail to work for me on Ubuntu. I felt like sharing this with all of you, so you can probably take advantage of it.

If you have any questions, remarks, comments or suggestions regarding this document, do not hesitate to contact me by e-mail: mailto:max_DOT_wiertz_AT_gmail_DOT_com.

Читайте также: