Mail on main domain, yunohost on subdomain

, ,

Hi there,

I have a question to get yunohost running.
I’m hosting a fairly big nextcloud instance on my homeserver. which has its own domain (ex. mydomain.org).

I would love to use yunohost, to manage mails on mydomain.org and access the nextcloud on mydomain.org.

Right now yunohost runs on a vps and should be accessible under yunohost.mydomain.org.
Can I achieve to manage mails through yunohost under mydomain.org?

I searched the forum and haven’t found a solution yet.

Best regards!
Samuel

1 Like

Hello,

If I understand your problem well, I think I found a solution. If your main domain is registered in yunohost domains (in the administration), then you can edit an user in the administration and chose the correct domain when defining his email address, you can also edit all the aliases. You may have to tweak your DNS configuration a bit so that mails work on main domain (I used the generated DNS config in the “Domains” menu in the admin).

Hope that will solve your problem, if not I’m afraid I can’t be of any help :confused:

1 Like

Hi!

Thanks for your reply - I already consiedered this thread dead :slight_smile:

Just to be sure, to understand you the right way, I would

  1. Add my domain to the domains
  2. Only add the DNS entries for mail and preserve the rest, so that the nextcloud remains functional
  3. Add user(s) that have mail on the main domain

Thank you very much for your help!
Samuel

Okay,

it worked, like you said.

For reference i try to describe my setup in some detail:

Domain

  • Yunohost runs under yunohost.example.com, the DNS is set up according to the generated DNS config by Yunohost
  • The domain example.com was added as well, but only the DNS entries corresponding to mail were added.
    Additionally the mx entry for example.com points to 10 yunohost.example.com

Mail with wildcard aliases

  • The users get wildcard aliases to their primary mail in the form of *username@example.com this is achieved by a post-user-create-hook which adds the wildcard to the postfix config.
  • Postfix should recognize these aliases, therefore /etc/postfix/main.cf needs to be altered, to preserve this change upon upgrades I created a conf-regen-hook. After upgrade one should execute sudo yunohost conf-regen postfix --force then the updated config can take place with the reference to the regex-aliases.
  • Reference: Mail alias with wildcard - #4 by Martin

/etc/yunohost/hooks.d/conf_regen/20-postfix_modifications

#!/bin/bash

action=$1
pending_dir=$4
postfix_conf=$pending_dir/../postfix/etc/postfix/main.cf

# Check if everything is in place
[[ $action == "pre" ]] || exit 0
[[ -e $postfix_conf ]] || exit 0

# Include Regex Aliases
awk -i inplace '{if (/^virtual_alias_maps = /) {$0=$0 ",regexp:/etc/postfix/aliases-regexp"}; print}' $postfix_conf

# Comment out sender mismatch verification
# To send mails from *@mydomain.org
sed -e '/reject_sender_login_mismatch/ s/^#*/#/' -i $postfix_conf

/etc/yunohost/hooks.d/post_user_create/10-new-user-postfix-regex

#!/bin/bash

echo "/.*$YNH_USER_USERNAME@example\.com/ $YNH_USER_MAIL" | cat - /etc/postfix/aliases-regexp > temp && mv temp /etc/postfix/aliases-regexp

postmap /etc/postfix/aliases-regexp
systemctl restart postfix

After all, I’m no expert in all of this, so if you find errors or wildly exotic handling of configs, I’m more than happy if you tell me.
Best regards
Samuel

1 Like