r-raymond / nixos-mailserver

A complete and Simple Nixos Mailserver
GNU General Public License v3.0
181 stars 27 forks source link

How to send email to multiple recipients #104

Closed joehealy closed 6 years ago

joehealy commented 6 years ago

How do you send email to multiple virtual accounts?

ie office@domain goes to account1@domain and account2@domain?

Adding office@domain to each of the accounts aliases attribute results in mail only being sent to one of the accounts

phdoerfler commented 6 years ago

This sounds like you want to create a mailing list albeit a small one. I have googled a bit and it seems with postfix you can do this:

# main.cf
virtual_alias_maps = hash:/etc/postfix/virtual

# virtual
updates@example.com user1@example.com, user2@example.com, # etc

I don't think this is possible (right now) when using NMS due to the way it creates the alias file. So IMHO you have two good options:

So what is it going to be?

r-raymond commented 6 years ago

I wouldn't mind a PR for this at all. Nonetheless, normally this problem is solved by adding additional recipients to the sending mail.

The-M1k3y commented 6 years ago

As a workaround you could use a sieve script and two distinct accounts:

require ["copy"];
redirect :copy "user2@example.com";

(Untested but should work)

joehealy commented 6 years ago

@phdoerfler @r-raymond good to know there is not existing functionality for this - I'd looked, but couldn't see it anywhere.

I'm happy to try to put together a pull request. The simplest case would be just to permit anything at all in the extraVirtualAliases, though I'm not sure where the restrictions are set right now. See below:

Right now, when I try the following:

extraVirtualAliases = {
   "info@domain1" = "u1@domain1,u2@domain1,u3@domain1";
};

I get the following error:

error: The option value mailserver.extraVirtualAliases.info@domain1' in/etc/nixos/mailserver.nix' is not of type `one of "u1@domain1", "u2@domain1", "u3@domain1"'.

How is this restriction enforced?

r-raymond commented 6 years ago

Thanks for putting work into this! It is inforced by the type:

type = types.attrsOf (types.enum (builtins.attrNames cfg.loginAccounts));

so the right hand side has to be an enum with possible choices defined by the loginAccounts. The conundrum is that we can't really change this to all possible values for comma seperated addresses (which would grow with n!). What we could do though is add a list type to the right hand side, so that multiple assignments are allowed and collected. Then it could be

"info@..." = "u1@..."
"info@..." = "u2@..."
...

Of course the logic writing the valiases file would need modifications.