Skip to content

Conversation

kacpersaw
Copy link
Contributor

@kacpersaw kacpersaw commented Oct 8, 2025

This PR adds a fake SMTP server for scale testing. It collects emails sent during tests, which you can then check using the HTTP API.

Changes

  • Added mock SMTP server
  • Added coder scaletest smtp CLI command
  • Implemented HTTP API endpoints to retrieve messages by email
  • Added auto-purge to prevent memory issues

HTTP API Endpoints

  • GET /messages?email=<email> – Get messages sent to an email address
  • POST /purge – Clear all messages from memory

The HTTP API parses raw email messages to extract the date, subject, and notification ID.

Notification IDs are sent in emails like this:

<p>
  <a href="http://127.0.0.1:3000/settings/notifications?disabled=4e19c0ac-94e1-4532-9515-d1801aa283b2"
     style="color: #2563eb; text-decoration: none;">
    Stop receiving emails like this
  </a>
</p>

CLI

coder scaletest smtp --host localhost --port 33199 --api-port 8080 --purge-at-count 1000

Flags:

  • --host: Host for the mock SMTP and API server (default: localhost)
  • --port: Port for the mock SMTP server (random if not specified)
  • --api-port: Port for the HTTP API server (random if not specified)
  • --purge-at-count: Max number of messages before auto-purging (default: 100000)

Copy link
Contributor Author

@kacpersaw kacpersaw force-pushed the kacpersaw/scaletest-smtp-mock-server branch from 5830a76 to 20790fc Compare October 8, 2025 16:02
if err := s.smtpServer.Start(); err != nil {
return xerrors.Errorf("start SMTP server: %w", err)
}
s.smtpPort = s.smtpServer.PortNumber()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are doing this so that you can leave the port initially set to 0 and then later query the running port. It feels like a sharp edge, though, that s.SMTPAddress() will show you a 0 port until you start the server. Is there any reason why we don't want to just start the server immediately on New()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of allocating ports in New(). IMO It should only be responsible for initialization. We could remove New() and let Start() handle init instead, since we don't do any complicated stuff in there. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like:

srv := new(Server)
err = srv.Start(ctx, config)

I think that's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants