Struggling to Configure SMTP in Discourse with Azure Communication Service

Hey everyone,

I’ve been wrestling with setting up SMTP on my Discourse installation, and it’s been quite the challenge. I’ve delved into numerous posts like this one without luck.

Here’s the scoop: I suspect my issues are tied to the format and length of the username and password that I’m required to use. I’m tapping into Azure Communication Service for my SMTP server, which demands a specific configuration involving an Azure Entra App (formerly Azure Active Directory).

To cut to the chase, the username format looks something like this (not actual credentials, just an example):

<Azure Communication Services Resource name>.<Entra Application Id>.<Entra Application Tenant Id>

Here’s an example: my-communication-service.7d8233e0-c230-4468-a2de-1d03aa64bb71.49ba4f9c-3b18-43df-b5fd-5e203ba6e031

For more details, check out this link.

Meanwhile, the password needs to adhere to an Azure-generated secret format, such as:

b_C8Q~WjHH~MtFQptMj8wR1KroOZYigGy3A3Zc5M

Now, I’ve got this setup working smoothly in C# with similar credentials.

 private static void SendMail()
    {
        string smtpAuthUsername = "my-communication-service.7d8233e0-c230-4468-a2de-1d03aa64bb71.49ba4f9c-3b18-43df-b5fd-5e203ba6e031";
        string smtpAuthPassword = "a~C8Q~WjHH~MtFQptMj8wR1KroOZYigGy3A3Zc5M";

        string sender = "DoNotReply@my-domain.com";
        string recipient = "admin@my-domain";
        string subject = "You a chosen";
        string body = "One gorgeous body";
        string smtpHostUrl = "smtp.azurecomm.net";

        using (var client = new SmtpClient(smtpHostUrl))
        {
            client.Port = 587;
            client.Credentials = new NetworkCredential(smtpAuthUsername, smtpAuthPassword);
            client.EnableSsl = false;

            var message = new MailMessage(sender, recipient, subject, body);

            try
            {
                client.Send(message);
                Console.WriteLine("The email was successfully sent using Smtp.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Smtp failed with the exception: {ex.Message}.");
            }
        }
    }

However, when I try to implement these settings in Discourse, things start acting up. Here’s what I’ve got configured:

DISCOURSE_SMTP_ADDRESS: smtp.azurecomm.net
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: "my-communication-service.7d8233e0-c230-4468-a2de-1d03aa64bb71.49ba4f9c-3b18-43df-b5fd-5e203ba6e031"
DISCOURSE_SMTP_PASSWORD: "b_C8Q~WjHH~MtFQptMj8wR1KroOZYigGy3A3Zc5M"
DISCOURSE_SMTP_ENABLE_START_TLS: true
DISCOURSE_SMTP_DOMAIN: my-domain.com
DISCOURSE_NOTIFICATION_EMAIL: DoNotReply@my-domain.com

However, despite this setup, I keep getting an authentication error as per the log snippet:

Job exception: Net::SMTPAuthenticationError

I’ve experimented with enclosing the username and password in various ways—single quotes, double quotes, or even leaving them out entirely. But the outcome remains the same.

Any pointers or suggestions on what else I could try would be greatly appreciated.

1 Like

Hello, I have met the same issue with Azure Communication Service.

According to the Microsoft Docs, I think it might be that Microsoft Entra must be supported by the application but Discourse unfortunately doesn’t support that.

Meanwhile, I’m looking forward to any other available methods, too.

I ran into the same issue and found this topic on a web search, and it appears that (just like with the Microsoft 365 email servers before they dropped password-based authentication) only AUTH LOGIN is supported, not AUTH PLAIN which is the default in Discourse at the time of this writing.

Setting DISCOURSE_SMTP_AUTHENTICATION: login in the container configuration makes email work. Of note is, as well, that by default the only ‘from’ email allowed is the default DoNotReply@domain.example- if you don’t set this, your emails will get rejected with “550 5.3.5 Email sender’s username is invalid”.

4 Likes

Looks like this is now fixed, thanks to @justinm

I have also been trying to set it up following the suggestion here. However, I also could not get it working but I can’t find any logs regarding SMTP issue. Do you know which log file should I look for. Thanks.

You’ll want to check the /logs URL.

If you’re debugging, you might be farther ahead trying the rake 'emails:test[your_email]' task.

You can also set environment variables to try different things without needing a container rebuild, e.g.:

$ DISCOURSE_SMTP_PORT=587 DISCOURSE_SMTP_USER_NAME=bilbo DISCOURSE_SMTP_PASSWORD=ring rake emails:test'[frodo@shire.net]'

I am using the discourse/discourse 2025.12.0 image. Interesting, even if i do not set DISCOURSE_SMTP_PASSWORD, the production.log does not display any errors as if the admin user registration task doesn’t get called. The only log available is

Started POST “/finish-installation/register” for xxx at 2026-01-09 16:48:11 +0000
Processing by FinishInstallationController#register as HTML
Parameters: {“authenticity_token”=>“xxx”, “email”=>“xxx”, “username”=>“xxx”, “password”=>“[FILTERED]”, “commit”=>“Register”}
Redirected to xxx

Completed 302 Found in 489ms (ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 131.6ms)

You’re looking for https://whateveryoursiteis.com/logs

Edit, issue fixed. Problem was user name env variable should be DISCOURSE_SMTP_USER_NAME instead of DISCOURSE_SMTP_USERNAME.

The below configuration work:

DISCOURSE_SMTP_USER_NAME: <Azure communication service SMTP user name (does not need to be <Azure Communication Services Resource name>.<Entra Application Id>.<Entra Application Tenant Id>>
DISCOURSE_SMTP_PASSWORD: xxx
DISCOURSE_SMTP_DOMAIN: yourdomain
DISCOURSE_NOTIFICATION_EMAIL:  DoNotReply@yourdomain
DISCOURSE_SMTP_AUTHENTICATION: login
DISCOURSE_SMTP_ENABLE_START_TLS: true

you can rake admin:create from the container to create an account directly

Also, I’ve just learned that the way we handle environment variables has changed - we no longer look at them except at container boot.

If you want to test a different value, you need to edit /var/www/discourse/config/discourse.conf

:+1: