I have a few recently migrated domains with over 200 mail accounts and need to modify Postfix to allow clients to connect using firstname.lastname@example.org format rather than user.account.
Where can I change this for the domain or the whole system with Virtualmin or Webmin?
Whenever a new email account is created, the format used for that account is set in System Settings -> Server Templates -> Default -> Mail for Domain.
To use the user@domain format, look at the bottom of that screen for an option named “Format for usernames that include domain”, which you can change that to user@domain.
How does that change the functionality of the 200+ mail accounts already created using the user,account format?
Well, changing the names of users after they’re created is a lot more complex
You can do it, but it requires custom scripting using the command line tools.
If you run “virtualmin modify-user” from the command line, you’ll see a list of options there.
You should be able to use the --newuser option to change the username to your preferred format.
What you’d need to do is loop through all the Virtual Servers on your system (which you can do with “virtualmin list-domains”, and then loop through each account in those domains (with “virtualmin list-users --domain DOMAIN_NAME”), and use the --newuser option to change the accounts.
Of course, I’d recommend testing that on one account first before you run that against all of them.
If you’re able to remove them all and start over, that may be a simpler solution, as all you’d need to do is update the email format setting in the server templates before performing the migration.
Thanks for the info Eric!
It’s a pain due to the fact the mail accounts have been migrated and the clients are not able to connect due to the different connection style (account name format) and having all those people change their mail clients is not an option.
Ok Finding a little info now.
With the template changed to @ if I add a new mail account everything works great.
If I change and change back the name of an existing account to let it take on the @ style it fails and it looks like it is due to the entry in /etc/postfix virtual being strange.
Old account structure:
New account structure:
Edited old account structure:
Edited new account structure:
Is this a bug in virtualmin?
If I manually edit the virtual file and update the db to change user3/@ to user3- I still get failures due to user not found when sending to user3@
Any Ideas how I can modify all old manually so that virtualmin and postfix are both happy?
Will the --newuser option change the account differently that doing it through the GUI?
Where can I find instructions on the virtualmin CLI commands, what they do and how to use them?
They’re largely self-documenting, actually.
If you run “virtualmin” from the command line, you’ll see a list of available options.
Once you find the option that does what you’re after, you can then run “virtualmin OPTION_NAME” for more options, and example usage.
If you prefer to view all that using the web though, there’s instructions available here:
You said to use --newuser but is that just for making a new account? How does that relate to my need to modify an account? I just tried to use the virtualmin modify-user --username username to try to have the script change the users name to itselft to update to the new @ and it’s not doing anything.
When using “modify-user”, the --user parameter states which user you’re updating. The --newuser parameter is where you’d specify what the new username should be. Except that in your case, the --user and --newuser would be the same… that should get it to regenerate the usernames and to put them into the user@domain format.
I had figured out the format:
virtualmin modify-user --domain example.com --user username --newuser username
Has no effect and generates this output:
New username is the same as the old
If I change the username and then change it back
virtualmin modify-user --domain example.com --user username --newuser username1
virtualmin modify-user --domain example.com --user username1 --newuser username
It works and the smtp connection starts working from the client but then the imap connection fails so the user cannot receive. I see that doing the above creates an alias for the user even though there is an actual mail user. Why is it doing this and is this normal?
Like this virtualmin:
username Address email@example.com
Like this in /etc/postfix/virtual
Why are names in the virtual file when a new account created in this format:
and all mail services work fine for them
but accounts where the username is changed are in this format
and they don’t work?
Ok now I am stuck and in TROUBLE due to the virtualmin CLI --newuser command.
When changing a working account that is in this format username.account it makes the account no longer functional with User unknown in virtual alias table errors when attempting to send to this account.
When I do the change I do it twice. first away from user to a temporary user1 and then back to user. Like this:
virtualmin modify-user --domain example.com --user changeme --newuser changeme1;
virtualmin modify-user --domain example.com --user changeme1 --newuser changeme;
I get successful returns on both commands and the account is able to be accessed through the 20000 webmail interface.
When looking in the virtual file or in the virtualmin virtual domain aliases page I see that the account has an entry like this:
Is virtualmin breaking these accounts with a bad virtual alias entry?
How do I fix this???
OK I Found the issue and it looks like it is a bug in Virtualmin!
using the --newuser command fails to do two things to make the changed account a functional email account when switching from user.account postfix style to firstname.lastname@example.org style.
It doesn’t add a user-domain style user to /etc/passwd
It doesn’t correctly then enter the alias in /etc/postfix/virtual
It should enter
I’m trying to do exactly this as I inadvertently didn’t set the template correctly when migrating a few Plesk virtual domains.
I have a user iain.domain that I want to change to email@example.com. From the posts above it’s clear I need to change the user to an intermediate one and then back if I want to keep the same name.
When I create a new user from the CLI all is fine it’s in the firstname.lastname@example.org format
When I use the CLI
e.g. virtualmin modify-user --domain domain.com --user iain --newuser iain2
it creates the new user as iain2.domain if the use was one that was created before hand. I know I could delete the user and create a new one but they all have existing mailboxes etc.
Anyone got any idea how to actually manage to do this?