Skip to content

Bug: Maximum call stack size exceeded when sending email verification code #982

@wail-asad

Description

@wail-asad

Description:

Bug Report: Email Verification Failure with Custom SMTP Server

When attempting to send an email verification code through the Stack Auth dashboard, the request fails with a 500 error and "Maximum call stack size exceeded" error.


Environment

  • Stack Auth Version: Latest (Docker deployment)
  • Deployment: Docker Compose with custom domain
  • Email Server: Mailu (self-hosted SMTP)
  • Node Version: v22.9.0
  • Domain: Custom domain with HTTPS

Steps to Reproduce

  1. Set up Stack Auth with custom SMTP configuration (see configuration below)
  2. Navigate to Stack Auth dashboard → Account Settings
  3. Click "Send Verification Email"
  4. Error occurs immediately

Expected Behavior

  • Verification email should be sent successfully
  • User should receive verification code at their email address

Actual Behavior

Frontend Error:

StackAssertionError: Failed to send request to https://authapi.example.com/api/v1/contact-channels/me/e606efe2-f80c-420e-bf70-0553da2d0dbd/send-verification-code: 500

Something went wrong. Please make sure the data you entered is correct.

Backend Error:

Captured error in route-handler: RangeError: Maximum call stack size exceeded

Email Configuration

Docker Environment Variables:

# SMTP Configuration (Mailu server)
STACK_EMAIL_HOST=mail-server
STACK_EMAIL_PORT=465
STACK_EMAIL_USERNAME=noreply@example.com
STACK_EMAIL_PASSWORD=your_password_here
STACK_EMAIL_SENDER=noreply@example.com

# Stack Auth API
NEXT_PUBLIC_STACK_API_URL=https://authapi.example.com
NEXT_PUBLIC_STACK_PROJECT_ID=412c863e-afb8-41ef-8c78-20414a58f26f

Email Server Details:

  • Server Type: Mailu (self-hosted)
  • Port 465: SSL/TLS (Working - verified independently)
  • Port 587: Not enabled
  • Port 25: Blocked by DMARC policy

Independent Email Test (Successful)

We verified the SMTP server works correctly outside of Stack Auth using the following test:

// test-email.js - Ran inside Stack Auth Docker container
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: 'mail-server',
  port: 465,
  secure: true,
  auth: {
    user: 'noreply@example.com',
    pass: 'your_password_here'
  },
  tls: {
    rejectUnauthorized: false
  }
});

// Test email send
transporter.sendMail({
  from: 'noreply@example.com',
  to: 'test@example.com',
  subject: 'Test Email',
  text: 'This is a test email',
  html: '<h1>Test Email</h1><p>Email sent successfully!</p>'
}).then(info => {
  console.log('✅ Email sent successfully!');
  console.log('Message ID:', info.messageId);
  console.log('Response:', info.response);
}).catch(err => {
  console.error('❌ Error:', err.message);
});

Result:

✅ Connection successful!
✅ Email sent successfully!
📧 Message ID: <46d1e4a1-b81d-f6c7-4825-a5e89f1f7943@nextscholar.net>
📊 Response: 250 2.0.0 Ok: queued as E3D7D200CB5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions