# Rails

Connect Action Mailer to Sendy for your Rails application.

Before you begin, verify a sending domain and create an [API key](https://usesendy.com/docs/authentication). Keep the key in your application server’s secret configuration.

## Configure Rails

Add these settings inside the existing Rails.application.configure block. Use the matching environment file for development, and restart the application after changing it.

Use this configuration:

config/environments/production.rb

```
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
  address: "smtp.usesendy.com",
  port: 2525,
  user_name: "apikey",
  password: "API_KEY",
  authentication: :plain,
  enable_starttls_auto: true
}
```

Replace `API_KEY` with your full Sendy API key and the sender with an address on your verified domain. Use STARTTLS on port 2525 with the literal username `apikey`. See [Rails email documentation](https://guides.rubyonrails.org/action_mailer_basics.html).

## Send a test email

Open your application’s shell:

Open shell · terminal

```
bin/rails console -e production
```

Replace the recipient with your test address, then run:

Send a test email

```
ActionMailer::Base.mail(
  from: "My App <noreply@example.com>",
  to: "recipient@example.com",
  subject: "Welcome",
  content_type: "text/html",
  body: "<h1>Welcome</h1><p>Your account is ready.</p>"
).deliver_now
```

Use the same transport with your application’s mailers. Set their default from address to your verified sender.

## Check the result

Open [Emails](https://usesendy.com/emails) to confirm the message was queued and follow its status. Successful SMTP submission confirms queuing, not inbox delivery. See [Errors](https://usesendy.com/docs/errors) for failure guidance.
