Mailgun Email Service Fails on AppHarbor Deployment with C#

I’m having trouble with my email functionality when deploying to AppHarbor. The emails work perfectly on my local machine but fail once deployed.

string mailDomain = ConfigurationManager.AppSettings["MG_DOMAIN"];
string secretKey = ConfigurationManager.AppSettings["MG_SECRET_KEY"];
MailgunService emailService = new MailgunService(mailDomain, secretKey);
emailService.SendEmail(new System.Net.Mail.MailMessage("support@" + mailDomain, "[email protected]")
{
    Subject = "Welcome to our service",
    Body = "Thank you for signing up with us."
});

My configuration looks like this:

<add key="MG_SECRET_KEY" value="key-*********************" />
<add key="MG_DOMAIN" value="myapp.mailgun.org" />

The error I get on AppHarbor is System.Exception: Domain not found: smtp.mailgun.org

I think there might be additional configuration settings I need to use but I can’t figure out how to properly integrate them with the Mailgun client. Has anyone encountered this issue before?

That domain error usually means your MailgunService is defaulting to smtp.mailgun.org instead of your actual domain. Check if your MailgunService constructor is actually reading the MG_DOMAIN value from app settings. I’ve seen this happen when the service gets hardcoded to use the generic SMTP endpoint instead of your domain-specific one. Log the actual values from ConfigurationManager to make sure they’re not coming back null on AppHarbor. Config variables sometimes don’t load right in deployment. Also check if your MailgunService needs the full SMTP config instead of just domain and API key.