1 (edited by a3009158 2014-09-24 04:53:59)

Topic: Getmail, external mail retriever

======== Required information ====
- iRedMail version:  0.8.7
- Store mail accounts in which backend MySQL
- Linux/BSD distribution name and version: Debian
====

I just wanted to post this solution as I greatly enjoy iRedmail. This is a copy of a personal wiki and explains how to use getmail to retrieve external mail, optionally with a cronjob, to iRedmail.

==Installation==

Installing Getmail Before proceeding, make sure your system is up to date. If you’re using Debian, Ubuntu, CentOS, or Fedora, you’ll want to update your repositories and upgrade all packages to their latest versions. Select from the following commands, depending on what operating system you’re running:

apt-get update
apt-get upgrade

Since getmail is included by default in most distributions’ software repositories, its installation is straightforward. Issue the following command to install getmail on Debian and Ubuntu systems:

apt-get install getmail4

==Configuration==

* Create a configuration directory, and set the right permissions by executing: # mkdir -m 0700 ~/.getmail. The main configuration file often contains sensitive information, namely passwords in plain text.
* Create a configuration file, the default being: ~/.getmail/getmailrc. 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.

===Retrieving mail===

Here is an example getmailrc used with a gmail account.
[retriever]
type = SimpleIMAPSSLRetriever
server = imap.mailprovider.com
username =
password =

[destination]
type = Maildir
path =
user = vmail

[options]
verbose = 2
message_log = ~/.getmail/log

# retrieve only new messages
# if set to true it will re-download ALL messages every time!
read_all = false

# delete once retrieved
delete = true

# do not alter messages
delivered_to = false
received = false

Most people will like to add the following section to their getmailrc to prevent all the mail on the server being downloaded every time getmail is ran.

[options]
read_all = False

For this guide we will be storing our mail in the maildir format. The two main mailbox formats are mbox and maildir. The main difference between the two is that mbox is one file, with all of your mails and their headers stored in it, whereas a maildir is a directory tree. Each mail is its own file, which will often speed things up.

The maildir destination is the destination as found in the MySQL.

==== First Run ====
You can test the getmail retrieval with the following command
#getmail

If it works fine, you can create a cronjob for getmail to run every n hours/minutes. Type crontab -e to edit cronjobs, and enter the following:
  */1 * * * * /usr/bin/getmail
That will run getmail every minute.

Also, to quiet getmail down, we can reduce its verbosity to zero by adding the following to getmailrc.

[options]
verbose = 0

====More than one Email account with getmail====
By default, when you run getmail the program searches for the file getmailrc created as seen above. If you have more than one mail account you would like to get mail from, then you can create such a file for each email address, and then tell getmail to run using both of them.  Obviously if you have two accounts and two files you cannot have both of them called getmailrc. What you do is give them two different names, using myself as an example: I call one personal, and one university. These two files contain content relevant to my personal mail, and my university work mail respectively. Then to get getmail to work on these two files, instead of searching for getmailrc(default), I use the --rcfile switch like so: getmail --rcfile university --rcfile persona This can work with more files if you have more email accounts, just make sure each file is in the .getmail directory and make sure to  alter the cronjob to run the command with the --rcfile switches. E.g.

  */30 * * * * /usr/bin/getmail --rcfile university --rcfile personal

Obviously you can call your files whatever you want, providing you include them in the cronjob or shell command, and they are in the .getmail/ directory, getmail will fetch mail from those two accounts.

== Additional examples ==
[retriever]
type = SimpleIMAPSSLRetriever
server =
port =
username =
password =

[destination]
type = Maildir
path =
user = vmail

[options]
verbose = 2
message_log = ~/.getmail/log

# retrieve only new messages
# if set to true it will re-download ALL messages every time!
read_all = false

# delete once retrieved
delete = true

# do not alter messages
delivered_to = false
received = false

[retriever]
type = SimplePOP3Retriever
server = pop.mailprovider.com
username =
password =

[destination]
type = Maildir
path =
user = vmail

[options]
verbose = 2
message_log = ~/.getmail/log

# retrieve only new messages
# if set to true it will re-download ALL messages every time!
read_all = false

# delete once retrieved
delete = true

# do not alter messages
delivered_to = false
received = false

2

Re: Getmail, external mail retriever

Thanks for your sharing.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

3 (edited by shaiktharim 2014-10-18 19:38:42)

Re: Getmail, external mail retriever

Thanks for sharing and i would like to know the path location in Destination.

Im using iRedmailpro LDAP and i wanted to locate the path of maildir.

[destination]
type = Maildir
path = ? ( What is the default path of mailboxes)
user = vmail

Thanks in Advance.

Shaik

4

Re: Getmail, external mail retriever

For iRedMail LDAP backend, maildir path is stored in attribute 'homeDirectory' of mail user account.

----

Does my reply help a little? How about buying me a cup of coffee ($5) as an encouragement?

buy me a cup of coffee

5

Re: Getmail, external mail retriever

I have an SQL backend (Ubuntu 20.04 LTS), and when running getmail with the following configuration in getmailrc

[destination]
type = Maildir
path = /var/vmail/vmail1/mydomain.eu/u/s/e/user-2020.07.06.10.45.47/Maildir/
user = vmail

I get an error that the Maildir directory doesn't exist:

Configuration error: configuration file /home/mailadmin/.getmail/getmailrc incorrect (path: specified directory "/var/vmail/vmail1/mydomain.eu/u/s/e/user-2020.07.06.10.45.47/Maildir/" does not exist)

I did double check and the directory does exist.

Also, the vmail user has read/write/execute access:

drwx------ 9 vmail vmail 4096 Jul  6 10:55 /var/vmail/vmail1/mydomain.eu/u/s/e/user-2020.07.06.10.45.47/Maildir/

6 (edited by AGI 2020-07-07 03:14:40)

Re: Getmail, external mail retriever

It was a permissions issue because I had created the .getmail directory and getmailrc file in a user home directory.

After creating these in the root home directory, it worked.