Yunohost on Subdomain, Mail on main domain

My setup is described in this post: Yunohost on Subdomain, Mail on main domain - #4 by samuel-ynh

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

1 Like

Okay,

it worked, like you said.

For reference i try to describe my setup in some detail (2024-11-07 now with yunohost 12 update).

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
  • Reverse DNS-entry for the emails should be the yunohost subdomain (yunohost.example.com). Correct rDNS setup for mail-domain

Yunohost SSO Portal

With the new SSO on yunohost 12 the login page from the subdomain redirects to the main domain. To address this I created `/etc/ssowat/conf.json.persistent’ with:

{
    "domain_portal_urls": {
        "yunohost.example.com": "yunohost.example.com/yunohost/sso",
    },
}

From: 🚀 YunoHost 12.0 (Bookworm) release / Sortie de YunoHost 12.0 (Bookworm) - #84 by ljf

Empty landing page on yunohost 12

After loggin in on yunohost 12 no apps are shown. To fix this you can create a symbolic link in /etc/yunohost/portal/ for the subdomain which points to the file of the main domain

ln -s /etc/yunohost/portal/example.com /etc/yunohost/portal/yunohost.example.com

Unfortunately the symlink gets removed rather regularly. Therefore I created a systemd unit to create the symlink (this is definitely not an elegant solution).

/etc/systemd/system/yunohost-portal-symlink.service

[Unit]
Description=Create a symlink to enable the portal created for example.com on yunohost.example.com
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/ln -sf /etc/yunohost/portal/example.com.json /etc/yunohost/portal/yunohost.example.com.json

[Install]
WantedBy=multi-user.target

/etc/systemd/system/yunohost-portal-symlink.timer

[Unit]
Description=Starts the service to create the portal symlink to yunohost.example.com

[Timer]
OnCalendar=*:0,10,20,30,40,50
Unit=yunohost-portal-symlink.service

[Install]
WantedBy=multi-user.target

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

Backup

Okay, I’m just roughly documenting my setup here. Hence this chapter for backups.

I have a home-server running on the main domain with a working borg-backup. Therefore my backup solution is rather simple. The yunohost backup gets invoked once per day and only the 5 most recent backups are kept. Then on the home server runs a service which rsyncs the backups to the home server. This directory gets backupped with borg.

/home/example/yunohost-daily-backup.sh

#!/bin/bash


# Set date variable to current date
#printf -v date '%(%Y-%m-%d)T\n' -1
date=$(date '+%Y-%m-%d')
backupDir=/home/yunohost.backup/archives


# Invoke yunohost backup
yunohost backup create -n "${date}-daily"

# Remove old backups keep the newest 5 backups
# https://stackoverflow.com/questions/25785/delete-all-but-the-most-recent-x-files-in-bash
## daily backups
cd $backupDir && ls -tp | grep -v '/$' | grep  'daily' | tail -n +10 | tr '\n' '\0' | xargs -d '\n' -r rm --


## all other backups
cd $backupDir && ls -tp | grep -v '/$' | grep  -v 'daily' | tail -n +10 | tr '\n' '\0' | xargs -d '\n' -r rm --

/etc/systemd/system/yunohost-daily-backup.service

[Unit]
Description=Create a daily yunohost backup
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/bash /home/example/yunohost-daily-backup.sh

[Install]
WantedBy=multi-user.target

/etc/systemd/system/daily-backup.timer

[Unit]
Description=Starts the service to create a daily yunohost backup

[Timer]
OnCalendar=daily
Unit=yunohost-daily-backup.service

[Install]
WantedBy=multi-user.target

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

4 Likes

Updated the setup to yunohost 12.