Trouble Adding SMTP Relay with Username Format "orgname/mailservername"

Hi all,

I’m trying to add a new mail domain in Hestia and configure it to relay outgoing email through my own SMTP server, which is running Postal.

Postal uses a specific username format for SMTP authentication: organizationname/mailservername (e.g., acme/mainserver ). However, when I enter this as the SMTP username in Hestia, it gets rejected as an invalid username.

It seems Hestia doesn’t allow the slash (/ ) character in the SMTP username field. Is there a workaround or a way to bypass this validation so I can use my Postal SMTP server as a relay?

Any help would be greatly appreciated!

Hi @ivansalloum

You could workaround it modifying the function that checks the username.

Edit file /usr/local/hestia/func/main.sh and modify function is_username_format_valid

is_username_format_valid() {
        if [[ ! "$1" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]]; then
                is_string_format_valid "$1" "$2"
        fi
}

with this:

is_username_format_valid() {
        if [[ ! "$1" =~ ^[A-Za-z0-9._%+-]+[@|/][[:alnum:].-]+\.[A-Za-z]{2,63}$ ]]; then
                is_string_format_valid "$1" "$2"
        fi
}

As I said, this is a workaround that may or may not work (I didn’t test it). Also, it will be overridden in the next Hestia update.

Thanks for the suggestion!

I tried modifying the is_username_format_valid function as described, but unfortunately it didn’t work. Is there a service I need to restart, or do I need to restart Hestia entirely, for the changes to take effect?

Also, when a Hestia update overrides the file, would the SMTP relay configuration still work if it was already saved before the update? Or would it break again once the validation logic is restored?

What means didn’t work? Any error?

If you are adding a global smtp relay, check that the right data is in the file /etc/exim4/smtp_relay.conf. If you are adding it for a domain, check the same in this file /etc/exim4/domains/YourDomain/smtp_relay.conf (replace YourDomain with the actual data).

If the data is the right one, check the log /var/log/exim4/mainlog

Thanks for the follow-up!

By “didn’t work”, I meant that Hestia still flagged the username with the slash (/ ) as invalid in the UI – even after modifying the is_username_format_valid function. It doesn’t let me save the relay config through the panel using that format.

I did manage to get it working by manually editing /etc/exim4/domains/YourDomain/smtp_relay.conf and inserting the correct username there. After that, everything works fine and mail is relayed as expected, so the data in the file is good and Exim is handling it correctly.

The problem is just with the validation in the Hestia interface. Since I separate domains across different Postal servers, I can’t use a global SMTP relay, so I have to repeat this manual step every time I add a domain, which isn’t ideal.

Let me know if there’s a cleaner or more permanent way around this.

If you have modified the main.sh script, do you get the same problem when using the command line?

v-add-mail-domain-smtp-relay USER DOMAIN HOST [USERNAME] [PASSWORD] [PORT]

Yes, I still get the same error when using the command line:

Error: invalid Username format :: organizationname/mailservername

So even with the modified main.sh, the v-add-mail-domain-smtp-relay command doesn’t accept the Postal-style username with a slash (/).

As mentioned earlier, I can work around it by manually editing the smtp_relay.conf file after adding the relay, and that works fine with Exim. But it would be really helpful if Hestia could officially support usernames with slashes for those of us running our own SMTP servers using Postal, where this format is required.

Sorry, I didn’t pay attention to the regex and I wrote a wrong one. Use this function and try again, it should work from panel and from command line:

is_username_format_valid() {
        if [[ ! "$1" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]] && [[ ! "$1" =~ ^[A-Za-z0-9._%+-]+/[A-Za-z0-9._%+-]+$ ]]; then                  
                is_string_format_valid "$1" "$2"
        fi      
}

Ah, I overlooked that too, didn’t double-check the regex. With the corrected function, it’s now working from both the panel and the command line. Thanks!

That said, you didn’t get back to my earlier question:
If a future Hestia update overrides the main.sh file and restores the original validation logic, will the existing SMTP relay configurations (with the Postal-style usernames) continue to work, or will they break due to validation issues?

I assume they should keep working, since the validation only happens at the input stage, but I’d like to be sure.

Thanks again!

1 Like

Yes, you’re right.

1 Like

No, we are not right :stuck_out_tongue:

When rebuilding the mail domain, it will attempt to add the SMTP relay data again. If the function doesn’t include the added regex, it will fail.

This is the part of the rebuild that will fail:

❯ grep -A3 Relay /usr/local/hestia/func/rebuild.sh
                # Rebuild SMTP Relay configuration
                if [ "$U_SMTP_RELAY" = 'true' ]; then
                        $BIN/v-add-mail-domain-smtp-relay $user $domain "$U_SMTP_RELAY_HOST" "$U_SMTP_RELAY_USERNAME" "$U_SMTP_RELAY_PASSWORD" "$U_SMTP_RELAY_PORT"
                fi
1 Like

Okay, got it. So I guess the safest way for now is to add the relay using a placeholder username (without the slash), then manually edit the smtp_relay.conf file to insert the correct Postal-style username, as I had been doing. But now I’m not even sure if that manual edit will survive a rebuild or future update either.

If that gets overridden too, then I’m stuck! :sweat_smile:

I’ve been testing all weekend trying to find a clean solution that works with my Postal setup for managing personal inboxes across separate servers, but haven’t landed on anything that’s both reliable and manageable long-term. Would really love to see native support for these username formats at some point.

Thanks again for the clarification and your help throughout!

Open an issue in GitHub and I’ll try to add a PR to fix it.

I did:

1 Like

I’ve created the PR to fix it:

1 Like

Thanks!

1 Like