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

groups
pop3connector
v7

(Saito Benkei) #1

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.

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.

So:

Create the template-customs

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

Create these 2 fragments:

==========

vi 20destination

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

==========

vi 50options

[options]
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";
}

==========

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:

#!/bin/sh
#

for l in `/sbin/e-smith/db getmail print`
do
        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}" != "" ]
        then
                /sbin/e-smith/db getmail setprop ${GRKEY} Account ${GRACCOUNT}
        fi
done

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/* {
	weekly
	rotate 52
	compress
	notifempty
	missingok
}

==========

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

where:

  • 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.

BELOW there are obsloet 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

where:

  • 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.

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.

References:
https://www.linuxquestions.org/questions/linux-server-73/getmail-and-postfix-sendmail-command-duplicating-email-892754/
http://pyropus.ca/software/getmail/


Configure mail server with external domain name
NethServer 7.4 forward delivered messages
(Michael Kicks) #2

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


(Filippo Carletti) #3

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.


(Michael Kicks) #4

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


(Saito Benkei) #5

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


(Davide Principi) #6

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


(Saito Benkei) #7

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

changing

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

with

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

has resolved the problem


(Davide Principi) #8

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


(Saito Benkei) #9

http://pyropus.ca/software/getmail/configuration.html#destination-mdaexternal