Forwarding emails of login accounts with keeping local copy
Issue description
Cannot figure out how to simply configure nms to resend emails and also make possible user to log in with the same account.
What happened:
Mail arrives only to the local email, no resent to the external email. Can use account only for forwarding or only as a login account exclusively.
Technical details
I have configuration:
fqdn = "mx.example.com";
domains = [ "example.com" ];
forwards = {
"user@example.com" = "extern@external.com";
}
loginAccounts = {
"user@example.com".hashedPasswordFile = ...;
}
What is the right way to allow user to use that account as a login account, but also forward all emails to the external email address?
Find out, that this config yields file /etc/postfix/virtual
to having 2 lines:
user@example.com user@example.com
user@example.com extern@external.com
My hypothesis is, that postfix uses only the first one, so sending to the external email not hapenning, also seen in logs.
I changed the generation of file virtual to merge lines with the same first column with the following snippet (i am not much nix user):
virtual = let
allVirtuals = all_valiases_postfix ++ catchAllPostfix ++ forwards;
groupedVirtuals = lib.lists.groupBy
(line: builtins.head (lib.strings.splitString " " line)) allVirtuals;
concatenateLines = lines:
builtins.concatStringsSep "," (builtins.map (line:
builtins.concatStringsSep " "
(builtins.tail (lib.strings.splitString " " line))) lines);
in lib.concatStringsSep "\n"
(lib.mapAttrsToList (key: lines: key + " " + (concatenateLines lines)) groupedVirtuals);
It generates:
user@example.com user@example.com,extern@external.com
Now it works for my needs, but i guess there is a simpler way..