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.