HowTo: To deliver mails downloaded with POP3 Connector (getmail) to a email group in Nethserver NG 7.x

Apparently getmail doesn’t permit do deliver downloaded mails to a email group but only directly to email accounts.

With some modifications at configuration scripts it’s possible to change this behaviour.

This workaround resolves other 2 things:

  • Sieve filters don’t work in Webtop when you use pop3 connector
  • Any forward mail set in the user panel doesn’t work when you use pop3 connector

Unluckly these modifications are overwritten by POP3 connector dashboard in some cases so it’s necessary to pay attention.

I also enabled a better log of getmail.


Create the template-customs

mkdir -p /etc/e-smith/templates-custom/getmailrc
cd /etc/e-smith/templates-custom/getmailrc

Create these 3 fragments:


vi 10retriever

    my $retr = $account->prop('Retriever') || 'SimplePOP3Retriever';
    my $server = $account->prop('Server') || 'localhost';
    my $user = $account->prop('Username') || '';
    my $pass = $account->prop('Password') || '';
    my $isgoogle = $account->prop('IsGoogle') || '0';
    $OUT .= "type = $retr\n";
    $OUT .= "server = $server\n";
    if ($isgoogle == 0) {
        $OUT .= "username = $user\n";
    } else {
        $OUT .= "username = recent:$user\n";
    $OUT .= "password = $pass\n";


vi 20destination

type = MDA_external
path = /usr/sbin/sendmail
    my $user = $account->prop('Account') || 'root';
    $OUT .= "arguments = (\"-i\",\"-f %(sender)\",\"$user\")";
user = vmail
group = vmail


vi 50options

read_all = false
    my $delete = $account->prop('Delete') || '0';
    if ($delete == 0) {
        $OUT .= "delete = true";
    } elsif ($delete < 0) {
        $OUT .= "delete = false";
    } else {
        $OUT .= "delete_after = $delete";
received = false
message_log_syslog = true
delivered_to = false
message_log_verbose = true
    my $user = $account->key || 'root';
    $OUT .= "message_log = \/var\/log\/getmail\/$user.log";


Create the action to automatically modify getmail db with correct information of group email when you create/modify POP3 Connectors from dashboard

vi /etc/e-smith/events/actions/nethserver-getmailgroups-conf

with this content:


for l in `/sbin/e-smith/db getmail print`
        GRKEY=`echo $l | cut -f 1 -d =`
        GRACCOUNT=`/sbin/e-smith/db getmailgroups printprop ${GRKEY} Account`
        GRACCOUNT=`echo ${GRACCOUNT} | cut -f 2 -d =`
        if [ "${GRACCOUNT}" != "" ]
                /sbin/e-smith/db getmail setprop ${GRKEY} Account ${GRACCOUNT}

then give it permissions:

chmod 554 /etc/e-smith/events/actions/nethserver-getmailgroups-conf
chown root:root /etc/e-smith/events/actions/nethserver-getmailgroups-conf

And link it to the correct positions

cd /etc/e-smith/events/nethserver-getmail-save
ln -s ../actions/nethserver-getmailgroups-conf S05change-getmailgroups-conf
cd /etc/e-smith/events/nethserver-getmail-update
ln -s ../actions/nethserver-getmailgroups-conf S05change-getmailgroups-conf 


Create the getmail log directory

mkdir -p /var/log/getmail


Create logrotate script

vi /etc/logrotate.d/getmail

/var/log/getmail/*.log {
	rotate 52


So we now have the infrastructure.

Now we have to create the POP3 connector relative to groups:

The dashboard doesn’t permit to put the email group as the destination, only the accounts and relative emails.

So we have to make manually some modification to the db.

Create a POP3 connector relative to email group via dashboard. In the “Deliver massages to” field, put the first email address shown.

Save the POP3 connector and disable it with the button at the right of POP3 connectors list.

From console make the correct association between POP3 Connector name and group email destination:

db getmailgroups set POP3ConnectorName getmail Account DestinationMail@domain.tld


  • POP3ConnectorName: it’s the name of then POP3 Connector account
  • DestinationMail@domain.tld: it’s the mail address of the group where the mail are to send

Then reenable the POP3 Connector

In this manner, every time a POP3 Connector is created/modified, the previous script /etc/e-smith/events/actions/nethserver-getmailgroups-conf is executed.

This script read data from getmailgroups db and applies the correct group email to the POP3 Connector before scripts are generated for downloading mail.

If these informations aren’t correcly showed in POP3 Connector, click on “Pop3 connector” menu at the left for refresh the visualization.

If you delete a POP3 Connector, the informations in getmailgroups db aren’t delete automatically.
To di it:

db getmailgroups delete POP3ConnectorName

If you want to modify the mail group of one of the POP3 Connector:

db getmailgroups setprop POP3ConnectorName Account DestinationMail@domain.tld

Then disable and reenable the POP3 Connector in the dashboard.

Gmail mailboxes or mail domains on Gmail/Google servers

For those who have already installed these scripts previously, add also the 10retriever script as explained at the top of the page

Gmail mail servers have a particular management of POP3: even if getmail signals not to delete a mail from the server and not to mark it as read (usually because rspamd has temporarily refused with a soft fail), Gmail marks it as already downloaded and no longer allows downloading.

This mode of operation is also noticeable when several users download from the same Gmail mailbox via POP3 with a few days cancellation policy from the server. In this case, the various users do not download all the mails because Gmail only makes them downloadable to the first POP3 that intercepts them.

To avoid this, it is necessary to insert the prefix “recent:” on the login of the mail in question, as well as configure the Gmail server as in the link below.

Using the following commands you can automatically enter/remove the prefix “recent:” from the relevant boxes login:

To activate the correct download from Google servers type

db getmail setprop POP3ConnectorName IsGoogle -1

To disable the correct download from Google (e.g. because the box no longer points to a Gmail/Google server) type

db getmail setprop POP3ConnectorName IsGoogle 0


  • POP3ConnectorName: it’s the name of then POP3 Connector account

At the end of the changes, type the following command to make them operational:

signal-event nethserver-getmail-save

Remember to disable the movement of mails in the “spam” folders at the webmail level of the e-mail manager (usually it can be done by disabling the antispam control on the webmail), otherwise these mails will not be downloaded from the pop3 connector.

Gmail doesn’t allow to do this, so it is necessary to create a script at gmail box level that moves the mails that are deposited in “spam” to “inbox”.

At the link below there is an article that explains how to create such a script:

BELOW there are obsolete informations I hope that they should not be used

Obsolete informations inside

Modify the db:

vi /var/lib/nethserver/db/getmail

Find the row relative to the POP3 connector we have created then modify the field after the “Account” field (it should be the third of the row) replacing the email with the email group where the mail have to be delivered.

Save the file and refresh the POP3 Connector dashboard panel.

We see that the delivery email relatives to the POP3 connector will be changed with the email group.
It’s possibile now to enable the POP3 connector clicking on the button at the right.

Please note that if we made some modifications to that POP3 connector, we need to make again the modification on the db file because the delivery email will be replaced with the first email in the account lists.

Instead to modify directly the db, it’s possible to try with the following command:

db getmail setprop POP3ConnectorName Account DestinationMail@domain.tld


  • POP3ConnectorName: it’s the name of then POP3 Connector account
  • DestinationMail@domain.tld: it’s the mail address of the group where the mail are to send

In this manner, it’s possible to make a script to utilize after modification to a POP3 connector account

If we create or make modification to POP3 connectors that delivery mails to accounts, we don’t have to make modification on db.

I’m trying these modifications on a server with some POP3 connectors and, for now, I don’t have any Issue

I don’t have the knowledge to modify dashboard to avoid the modifications of delivery email in the db and to show all the emails that are configured on the server in the “Deliver massage to” field.

Other infos

Do not remove manually /var/lib/getmail/oldmail-* files.
These are the list of already downloaded mail from provider that getmail uses to manage the “Delete downloaded messages:” field.
If you delete them, getmail download again all mails from the provider.



2018.10.23 - Made some changes in 50options script and /etc/logrotate.d/getmail configuration to avoid strange behaviour in logs rotation.

2020.03.06 - Made some changes for better management of Gmail mailboxes or with domains on Gmail mail servers.

2021.02.03 - Added notice to disable moving mails to “spam” folder in webmail.

2021.11.26 - added “-i” parameter to sendmail (20destination fragment) to to avoid the truncation of the email download in case there is a line with only a dot and the next one is empty.

See parameter “-i” in Postfix manual - sendmail(1)


@dev_team any chance to implement in NethGUI/Cockpit this kind of setting?

I will help to review a pull request.
I think that we must discuss pro and cons of both solutions.
If there’s no clear winner, we could implement both.

I’m assuming this scenario as a useful option for getmail, not to exclude current scenario (drop mail on a single mailbox.

This configuration works with a single user too and resolves a issue when the account has a mail forward configured.

What happens if a forwarded message bounces for any reason? Who receives the bounce?

The bounce goes in the admin mailbox of the server… but… maybe changing this configuration it works (I tried two minutes ago)

in /etc/e-smith/templates-custom/getmailrc/20destination


$OUT .= "arguments = (\"-Ac\",\"$user\")";


$OUT .= "arguments = (\"-f %(sender)\",\"$user\")";

has resolved the problem

1 Like

What is %(sender)? How does it get its value?

Is there still hope this is transparently implemented?

1 Like

Updated documentation for better management of mailboxes on Gmail or domains with mail servers on Gmail/Google