Minimal Ruby on Rails example that sends test mail through Mailexam SMTP via Action Mailer.
Based on the Mailexam Ruby on Rails guide.
- A Mailexam account and a project with SMTP credentials.
- Ruby 3.2+ and Bundler.
From your Mailexam welcome email or dashboard:
| Variable | Description |
|---|---|
MAILEXAM_LOGIN |
SMTP login (for example, xxxxx) |
MAILEXAM_PASSWORD |
SMTP password (paired with the login) |
| Host | {MAILEXAM_LOGIN}.mailexam.ru (built in config/initializers/mailexam_mailer.rb) |
- Install dependencies:
bundle install- Copy the example environment file and fill in your credentials:
cp .env.example .env- Edit
.env:
MAILEXAM_LOGIN=YOUR_LOGIN
MAILEXAM_PASSWORD=YOUR_PASSWORD
MAILEXAM_PORT=587
MAIL_FROM=noreply@example.test- Run the server:
bin/rails serverThe server listens on http://127.0.0.1:3000 by default.
- Send a test message:
curl -X POST http://127.0.0.1:3000/mail/test \
-H 'Content-Type: application/json' \
-d '{"to":"user@example.test","subject":"Test","body":"Hello"}'The message appears in the Mailexam dashboard → your project → inbox.
bin/rails consoleTestMailer.with(
to: "user@example.test",
subject: "Ruby on Rails + Mailexam",
body: "Mailexam test from Rails"
).test_email.deliver_now| Variable | Required | Default | Description |
|---|---|---|---|
MAILEXAM_LOGIN |
yes | — | SMTP login; also used to build the host name |
MAILEXAM_PASSWORD |
yes | — | SMTP password |
MAILEXAM_PORT |
no | 587 |
SMTP port (587, 2525, or 25) |
MAIL_FROM |
no | noreply@example.test |
Sender address (any test address is fine) |
PORT |
no | 3000 |
HTTP listen port |
For ports 587 and 2525, STARTTLS is enabled (enable_starttls_auto: true). For port 25, it is disabled.
.
├── Gemfile
├── config/initializers/mailexam_mailer.rb
├── app/mailers/test_mailer.rb
├── app/controllers/mail_controller.rb
├── config/routes.rb
├── .env.example
├── Dockerfile # for local debugging only
└── docker-compose.yml
Docker is provided for local debugging. For day-to-day development, run the app on the host with bin/rails server (see above).
cp .env.example .env
# edit .env with your credentials
docker compose up --buildThen call the same endpoint on the mapped port:
curl -X POST http://127.0.0.1:3000/mail/test \
-H 'Content-Type: application/json' \
-d '{"to":"user@example.test","subject":"Test","body":"Hello"}'Inside the container the server binds to 0.0.0.0:3000.
Set these secrets in your CI environment:
variables:
MAILEXAM_LOGIN: $MAILEXAM_LOGIN
MAILEXAM_PASSWORD: $MAILEXAM_PASSWORD
MAILEXAM_PORT: "587"
MAIL_FROM: "noreply@example.test"After sending a message in a test, verify delivery via the Mailexam API.
In tests you can use delivery_method = :test and ActionMailer::Base.deliveries.
TLS or authentication failed
- Host must be
{login}.mailexam.ru, where{login}matchesMAILEXAM_LOGIN. - Login and password must come from the same Mailexam project.
Port 587
enable_starttls_automust betrue.
Environment variables not picked up
- Restart
bin/rails serverafter changing.env.
Message not in the dashboard
- Open the inbox of the same Mailexam project.
- Ensure
perform_deliveries = trueand the app is not using the:testdelivery method.