Getmail for Beginners: A Step-by-Step Guide

Author

Reads 2.4K

Female Software Engineer Coding on Computer
Credit: pexels.com, Female Software Engineer Coding on Computer

Getmail is a popular email retrieval tool that helps you manage your emails from various accounts. It's especially useful for those who need to check and download emails from multiple accounts.

Getmail is designed to be a flexible and customizable solution, allowing you to tailor it to your specific needs. This flexibility is due in part to its use of a configuration file, which can be modified to suit your requirements.

To get started with Getmail, you'll need to install it on your system. The installation process is relatively straightforward, and you can find detailed instructions in the Getmail documentation.

Installation and Configuration

To install and configure getmail, you'll need to create a configuration directory and set the right permissions. This is done by executing `mkdir -m 0700 ~/.getmail`.

The main configuration file often contains sensitive information, so it's essential to keep it secure. You can create a configuration file, which is usually located in `~/.getmail/getmailrc`. A separate configuration file is needed for each mailserver to pick up mail from.

Credit: youtube.com, Ubuntu: How can I download attachments from emails through terminal using getmail? (2 Solutions!!)

To make getmail run automatically, you can create a cron job for the user. For example, if you're logged in as the user falko, you can create a cron job like this: `*/5 * * * * /usr/bin/getmail &> /dev/null`. This will start getmail every five minutes.

Here's a summary of the configuration options:

Installation

To install the software, you'll need to download the installer from the official website and run it on your computer. The installer is available for both 32-bit and 64-bit systems.

Make sure your computer meets the minimum system requirements, which include a 2.4 GHz processor, 4 GB of RAM, and a 1 GB hard drive.

The installation process is relatively straightforward and should take no more than 10-15 minutes to complete. You'll be prompted to agree to the terms of service and choose the installation location.

The software requires a restart after installation to complete the setup process. This is a normal part of the installation process and should not cause any issues.

Consider reading: Email App Thunderbird

Configuration

Credit: youtube.com, Installation and Server Configuration

Configuration is a crucial step in setting up getmail. To create a configuration directory, you'll need to execute the command `mkdir -m 0700 ~/.getmail`. This will create a directory with the right permissions to store sensitive information.

The main configuration file is usually located at `~/.getmail/getmailrc`, and it's recommended to create a separate configuration file for each mail server you want to use. If you decide to use a different configuration file, you'll need to explicitly pass it as an argument to the getmail command.

To configure getmail, you'll need to create a configuration file with at least two sections: `[retriever]` and `[destination]`. The `[retriever]` section should contain information about the mail server, such as the server name, username, and password. The `[destination]` section should specify where the retrieved emails should be stored, such as a Maildir or mbox account.

Here's an example of a basic configuration file:

You can also use the `SimplePOP3Retriever` type in the `[retriever]` section to retrieve emails from a POP3 server. The `Maildir` type in the `[destination]` section is used to store emails in a Maildir account. If you have an mbox account, you can use the `Mboxrd` type instead.

To prevent multiple copies of getmail from running simultaneously, you can use a utility like `setlock` or `flock`. This is especially important if you're using cron to run getmail periodically.

Proc?

Credit: youtube.com, Hunter PC-WIFI Communication Module - Installation and Setup

To use procmail with getmail, you need to invoke procmail as an external MDA. Procmail requires that one of two conditions be true: the message must begin with a Unix "From " line, or procmail must be invoked with the -f option supplying the envelope sender.

To generate and prepend the "From " line to the start of the message, you can set the MDA_external parameter unixfrom to True.

Procmail can be finicky, so make sure to check that your message meets one of the required conditions. If it doesn't, you'll need to adjust your configuration accordingly.

Here are the two conditions that procmail requires:

  • That the message begins with a Unix "From " line (the mbox message delimiter)
  • That procmail is invoked with the -f option supplying the envelope sender, so that it may generate the "From " line

Getting Started

Getmail is a command-line mail retrieval tool, so you'll need to open a terminal or command prompt to start using it.

It's designed to retrieve mail from POP3, IMAP4, and other mail servers, making it a versatile option.

Getmail uses a configuration file to determine which mail server to connect to and how to retrieve mail.

Credit: youtube.com, . GetMail

This configuration file is where you'll specify the server, username, and password.

You can use the getmail command to check the version of Getmail installed on your system.

The -v option stands for "verbose" and will display more information about the version.

Getmail is a free and open-source tool, which means it's available for anyone to use and modify.

Setup and Options

To set up getmail, you'll first need to create a configuration directory with the right permissions. This is done by executing $ mkdir -m 0700 ~/.getmail. The main configuration file often contains sensitive information, namely passwords in plain text.

The configuration file is usually located at ~/.getmail/getmailrc, and a separate configuration file is needed for each mailserver to pick up mail from. Configuration files other than the default, will have to be explicitly passed as arguments to the getmail command.

You can also add an [options] section to the configuration file to change getmail's default behavior. For example, you can use the verbose option to print messages about retrieved messages.

Options

Close-up of a hand holding a smartphone with settings menu on a bright yellow background.
Credit: pexels.com, Close-up of a hand holding a smartphone with settings menu on a bright yellow background.

You can customize getmail's behavior by adding an [options] section to your getmailrc file. This allows you to change the default settings, such as deleting messages from the remote server after retrieval.

The [options] section can contain various options, including verbose, read_all, delete, and message_log_syslog. For example, you can set verbose = 1 to print messages about retrieved messages.

To delete only messages older than ten days, you can add delete_after = 10 to the [options] section. This will instruct getmail to delete messages older than ten days from the remote server.

Here are some common options you can use in the [options] section:

You can also use the getmailrc file to specify the path to your maildir directory. For example, you can set path = ~/Maildir/ to specify the path to your maildir directory.

Overhead view of a person typing on a laptop in an office setting with crumpled papers and stationery.
Credit: pexels.com, Overhead view of a person typing on a laptop in an office setting with crumpled papers and stationery.

It's worth noting that you can also use the --rcfile option to specify a different getmailrc file. This can be useful if you have multiple mail accounts and want to use a different configuration file for each account.

To quiet getmail down, you can reduce its verbosity to zero by adding the following to your getmailrc file: verbose = 0. This will prevent getmail from printing messages about retrieved messages.

Preliminary Note

Before we dive into the setup and options of getmail, it's essential to note that I've tested it on a Debian Etch system. I used a local user called falko with the local email address [email protected] for the test.

To install getmail, we only need to run a single command, which is mentioned in the installation process.

Getmail can be installed easily, and it's a great tool for managing email accounts, especially for users like falko.

Will Deliver as Root?

People Working in the Office
Credit: pexels.com, People Working in the Office

Getmail won't deliver mail as root, even if you run it as the root user on a Unix-like system. It will drop privileges and switch to an unprivileged group and user ID before delivering to maildirs or mboxrd files.

You can specify the user explicitly, or let getmail use the owner of the maildir or mboxrd file.

Getmail will refuse delivery and print an error message if it attempts to deliver mail and finds it has UID 0 or GID 0.

What's a Dir?

A dir is a mail storage format that allows for safe and reliable delivery, even over NFS, thanks to its design that requires no file locking.

It was invented by D. J. Bernstein, the same person who created qmail, a popular email server software.

One example of a dir is the maildir format, which is natively supported by getmail.

Maildirs are detailed in the qmail documentation at qmail.org and also explained in a technical paper by D. J. Bernstein at cr.yp.to/proto/maildir.html.

Retrieving and Managing Emails

Credit: youtube.com, Outlook Tips & Tricks to Take Control of your Inbox

Retrieving emails is a breeze with getmail. Simply create a getmailrc file that matches your POP3 service's specifications.

You can start by using a getmailrc file with a Gmail account as an example, and then tweak it to fit your needs. Now, run getmail to test it out.

If everything works fine, you can schedule getmail to run automatically using a cronjob. To do this, type crontab -e to edit your cronjobs, and then enter the following command.

Managing multiple email accounts is also a piece of cake. You can create a separate getmailrc file for each account and run getmail with multiple --rcfile options.

For example, you might create a script in $HOME/bin/run-getmail.sh to make it easy to run getmail for all your accounts. This script can be a huge time-saver if you have a large number of email accounts.

Email Delivery and Management

Getmail's flexibility in email delivery and management is one of its standout features. You can sort messages based on who they're from, or what address appears in the To: or cc: header fields, or based on the Subject: field contents, by using a filtering MDA like maildrop or procmail.

Credit: youtube.com, SMTP New Transporter - A new way to manage emails • 4D Summit 2020 - Digital Experience

To do this, you'll need to pick a filtering MDA and call it from a getmail MDA_external destination. You can supply the -f option to procmail by using the delivered_to[options] parameter.

If you want to deliver messages to an mh folder, you can use the rcvstore command as an external message delivery agent (MDA) with getmail's MDA_external destination. This will work with either mh or nmh clients, but you'll need to ensure your $HOME/.mh_profile file is configured properly.

A different take: MH Message Handling System

Delivering Messages to MH Folder

You can deliver messages to an MH folder using getmail's external MDA support. This is a great option if you're already familiar with MH clients.

getmail can use the MDA_external destination to deliver messages to an MH folder. To set this up, you'll need to configure your $HOME/.mh_profile file properly.

You can indicate the path to your MH mail root in your $HOME/.mh_profile file with a line like this: MhMailRoot:~/Mail/.mh.

The MDA_external destination uses the rcvstore command to deliver messages to your MH folder. This command is included in MH clients like nmh.

To use MDA_external, you'll need to specify the path to the rcvstore command in your getmail configuration. This will depend on your MH or nmh installation.

Additional reading: Comparison of Email Clients

Conditional Message Delivery

Credit: youtube.com, How Do I Use Conditional Logic In Mail Merge? - TheEmailToolbox.com

You can get getmail to deliver messages to different mailboxes based on various criteria, such as the sender's email address, recipient's email address, or subject line.

To do this, you'll need to use a filtering MDA like maildrop or procmail, and call it from a getmail MDA_external destination. This is done using the delivered_to[options] parameter.

If you want to supply the -f option to procmail, you'll need to specify it in the delivered_to[options] parameter.

getmail can already deliver messages to maildirs, mboxrd files, or through external MDAs, so you don't necessarily need to re-inject with SMTP.

However, if you still want to use SMTP, you can use getmail's external MDA support to do so.

One thing to keep in mind is that getmail won't deliver mail as root, even if you run it as the root user on a Unix-like system. It will drop privileges before delivering to maildirs or mboxrd files.

You can specify the user explicitly, or let getmail use the owner of the maildir or mboxrd file.

If getmail attempts to deliver mail and finds it has UID 0 or GID 0, it will refuse the delivery and print an error message.

See what others are reading: Anti-Spam SMTP Proxy

Security and Safety

A Brown Delivery Box with Mailing Details
Credit: pexels.com, A Brown Delivery Box with Mailing Details

Getmail has built-in support for POP3-over-SSL and IMAP4-over-SSL, providing a secure way to retrieve emails.

You can also use getmail's external MDAs to invoke your virus scanning program during delivery, ensuring your emails are scanned for viruses before they reach your inbox.

If you're concerned about password security, you can use the password_command parameter to call an external program to read the password, rather than storing it in the config file.

Virus Scanning of Retrieved Messages

You can use getmail's message filtering options to virus scan retrieved messages with an external virus scanning program.

Getmail supports virus scanning with ClamAV, a popular open-source antivirus program. To use ClamAV with getmail, you need to add the StreamSaveToDisk option to your clamav.conf file.

ClamAV can be used in standalone or client/server configurations. In either case, you need to enable scanning from stdin by adding the StreamSaveToDisk option.

To use ClamAV without the clamd daemon, you can use a filter configuration that scans messages for viruses and drops infected emails. This configuration looks like this:

A man with glasses focused on editing a photo on his desktop computer in an office.
Credit: pexels.com, A man with glasses focused on editing a photo on his desktop computer in an office.

To use ClamAV with the clamd daemon, you would use a slightly different configuration that scans messages for viruses and delivers infected emails. This configuration looks like this:

You can also use an additional filter to change the name of the added filter header lines immediately after each filter is run.

F-Prot is another antivirus program that can be used with getmail. getmail user Kai Raven reports that getmail and F-Prot work fine together with a specific getmailrc filter configuration.

The wrapper script f-prot-wrapper.sh is a small shell script that can be used to integrate F-Prot with getmail.

Password Management

It's a good idea to store your password securely, especially if you're using a POP3 service like Gmail. You can call an external program to read the password instead of storing it in the config.

To do this, you would use the password_command parameter in your getmail configuration. Note that the password parameter overrides this one, so specify one or the other, not both.

A different take: Ubuntu One

Credit: youtube.com, Your Passwords Are in Danger: Why You Need a Password Manager Now!

For example, you can run an external program to read the password, which will then be used by getmail. This can be a more secure option than storing the password in the config.

You can set getmail to run every 10 minutes by adding the following line to your cronjob: "*/10 * * * * getmail".

Does Support SSL?

getmail has built in support for POP3-over-SSL and IMAP4-over-SSL, providing a secure way to retrieve emails. This is especially important for sensitive information.

The fact that getmail supports SSL is a significant security feature, giving users peace of mind when handling their emails.

Does Rewrite Headers?

getmail does not rewrite mail headers when it retrieves mail. Rewriting message header fields can cause a loss of critical technical information necessary to track down many mail problems.

The biggest problem with rewriting headers is that it can make it difficult to track down mail problems. getmail will add a new Received: header field and a new Delivered-To: header field, but it will not rewrite existing headers.

You can disable the creation of these header fields if you choose to do so.

Troubleshooting and Maintenance

Credit: youtube.com, How To Fix Cannot Get Mail, Mail Server Not Responding - Full Guide

Getmail can be configured to run in the background and check for new emails at regular intervals, but it may occasionally fail to fetch emails from the server. This is often due to a temporary network issue or a problem with the email server.

To troubleshoot this issue, you can check the log files to see if there are any error messages. According to the Getmail documentation, error messages are usually logged to a file specified by the "log" option in the configuration file.

If you're still having trouble, try restarting the Getmail service to see if it resolves the issue.

Found a Bug

If you think you've found a bug in getmail, don't panic. First, check the repository on GitHub to see if the issue has already been reported.

You should include at least the following information in your bug report: getmail version, Python version, any error message displayed, the output from running getmail with your normal options plus --dump, and if your problem is getmail not determining the proper local recipient, please include the output of running getmail with your normal options plus --trace.

Credit: youtube.com, Does Software Maintenance Include Bug Fixes and Updates? - Learn To Troubleshoot

Don't include confidential information in your report, as it may compromise your account security.

Some issues reported as bugs are actually not bugs at all. For example, if you see an error message indicating that the server you're trying to use does not properly uniquely identify messages, it's not a bug in getmail. Instead, it's a configuration issue that can be resolved by switching to the BrokenUIDLPOP3Retriever class or its SSL variant.

Here's a list of information you should include in your bug report:

  • getmail version
  • Python version
  • any error message which getmail displayed
  • the output from running getmail with your normal options plus --dump
  • if your problem is getmail not determining the proper local recipient, include the output of running getmail with your normal options plus --trace

Gmail Download Issue

If you're experiencing issues downloading mail from Gmail with getmail, it's not necessarily a problem with getmail itself. Google's Gmail service violates the POP3 protocol by removing messages from the POP3 view of the mailbox without the user issuing a DELE command.

There are a few reasons why this might be happening. One is that if getmail tries to download a message and it fails for any reason, Gmail will have "helpfully" deleted the message from the POP3 mailbox, even though getmail never issued a DELE command.

Credit: youtube.com, How to Fix Gmail Not Downloading Files On PC (New Update)

If your provider also offers IMAP access to your mailbox, try one of the IMAP retrievers instead. This can be a good solution if you're having trouble with POP3. Change your configuration so you're not leaving messages on the server, and use BrokenUIDLPOP3Retriever instead.

Here are some possible solutions to the Gmail download issue:

  • Try using an IMAP retriever instead of POP3.
  • Change your configuration to not leave messages on the server and use BrokenUIDLPOP3Retriever.
  • Talk to your mail hosting provider and see if they can fix their POP3 software.

If you're using OpenSSL 1.1.1 or higher, you may experience connection/SSL errors connecting to Gmail servers. This is because Gmail is failing the connection on the basis that SNI is not in use.

Explore further: Non Html Gmail

Fetching with Systemd

You can use Systemd/Timers to automate tasks, like fetching mail with getmail. Create a unit file for the timer to set the schedule.

To get started, you'll need to create a service file for getmail. This file will define the settings and behavior of the service.

Enable the user unit get_mail.timer to start the timer and get mail fetching up and running.

Temporarily Stop Cron Job

People Having a Meeting in an Office
Credit: pexels.com, People Having a Meeting in an Office

Temporarily stopping a cron job can be a lifesaver when your mail server is down and you don't want to see those annoying warning emails.

You can comment out the cron job by running $ crontab -e to edit your crontab file, placing a # character at the start of the line containing the call to getmail, and saving the changed file.

This will temporarily disable the cron job, and when you want to re-enable it, simply edit the file again and remove the # character.

Alternatively, you can use a flag file to tell the system whether or not to run the cron job. This involves changing your cron job to check for the presence of a certain file first, and not running the cron job if that file is present.

To create the flag file, simply touch a file with a specific name, and to delete it, use the rm command.

Advanced Features

Laptop showing email next to green plant, ideal for tech and productivity concepts.
Credit: pexels.com, Laptop showing email next to green plant, ideal for tech and productivity concepts.

Getmail's advanced features make it a powerful tool for managing your email inbox. It can run in daemon mode, allowing it to continuously check for new emails and perform actions on them.

One of the most useful features is the ability to use multiple mailboxes, making it easy to manage multiple email accounts with a single getmail instance.

Getmail's support for multiple protocols, including POP3 and IMAP, ensures compatibility with most email providers.

Sorting with Procmail

Sorting with Procmail is a powerful tool for managing your email. To get started, you'll need to edit your getmailrc to pass retrieved mail to procmail.

Procmail is a mail filter that can sort your email into different folders based on specific criteria. You can configure procmail to filter your mail by editing its configuration file.

For example, you can use procmail to sort mail into folders based on sender, recipient, or subject. This can help keep your inbox organized and make it easier to find specific emails.

How to Use SpamAssassin

Credit: youtube.com, How to reduce spam by optimizing Spam Assassin

To use SpamAssassin, you'll want to set it up in a client/server configuration with the spamd daemon. This involves using a configuration that filters messages through SpamAssassin.

In this configuration, you'll use a setup like the one described in the example, which includes the spamd daemon. This will allow you to filter messages effectively.

You can also use a configuration without the spamd daemon, but it's essential to note that this may not provide the same level of filtering as the client/server configuration.

For your interest: Apache SpamAssassin

Multiple Accounts and Software

To manage multiple accounts with getmail, you can create separate rc files for each account. This way, you can keep your personal and work emails organized in their own files, such as "personal" and "university".

You can then tell getmail to use these files by specifying the --rcfile switch. For example, you can run getmail with the command "getmail --rcfile university --rcfile personal".

If you have a large number of accounts, you can create a script to automate the process. For instance, you can create a script in $HOME/bin/run-getmail.sh that contains the command to run getmail with multiple rc files.

Multiple Accounts

Credit: youtube.com, MANAGE Multiple Google Accounts Like a PRO on One Computer!

You can have more than one email account with getmail by creating a separate getmail rc file for each account.

To do this, you'll need to create a file for each email address in the .getmail directory. For example, you might call one file "personal" and one file "university." These files will contain the specific settings for each email account.

You'll need to run getmail using multiple --rcfile options to tell it which files to use. This can be done by using the command getmail --rcfile university --rcfile personal.

If you have multiple accounts, you can also script this process for convenience. For example, you might create a script in $HOME/bin/run-getmail.sh that contains the getmail command with multiple --rcfile options.

Using Other Software

Using other software can be a great way to enhance your email management. Frankye Fattarelli, a getmail user, contributed to the integration of getmail with SpamAssassin and ClamAV.

The --report option in getmail sends the message to spam-blocker databases and tags it as spam in your bayesian database. This helps improve the accuracy of your spam filters.

Frankye Fattarelli's contributions show that getmail can be used with other software to create a more comprehensive email management system.

You can use getmail with other software to streamline your email workflow and reduce spam.

Viola Morissette

Assigning Editor

Viola Morissette is a seasoned Assigning Editor with a passion for curating high-quality content. With a keen eye for detail and a knack for identifying emerging trends, she has successfully guided numerous articles to publication. Her expertise spans a wide range of topics, including technology and software tutorials, such as her work on "OneDrive Tutorials," where she expertly assigned and edited pieces that have resonated with readers worldwide.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.