Rails Brevo SMTP 500 error on Render: host, port, free tier
A Rails app that sends through Brevo locally but returns a 500 on Render usually has one of two problems: a wrong or outdated SMTP host or credentials, or Render's free tier blocking outbound SMTP ports. Fix the settings, upgrade the instance, or send through Brevo's HTTPS API.
Sohail Hussain9 min readShort answer
- Read the exception class in your Render logs first. A timeout points to blocked SMTP or a wrong host, a 535 points to a wrong SMTP login or key, and a DNS error points to an old hostname.
- Use smtp-relay.brevo.com on port 587 with the SMTP login and SMTP key from Brevo, not your account password or an API key.
- If the connection still times out on a free Render service, move to a paid instance or send through Brevo's HTTPS API, which needs no SMTP port.
Your Rails app sends mail fine on your laptop, then returns a 500 on Render the moment a mailer runs after you add Brevo SMTP. The page tells you almost nothing; the real error is in the logs.
Why it happens
deliver_now raises when the SMTP connection or login fails. In production, Rails turns an unhandled exception in a controller into a generic 500, so the 500 is only a symptom. Three causes cover most cases, most common first:
- Wrong host. Older tutorials still show
smtp.sendinblue.combecause Brevo used to be Sendinblue. Brevo's setup article gives the SMTP server as smtp-relay.brevo.com. - Wrong credentials, or credentials that never reached production. A local
.envfile does not deploy to Render, so the variables arenilthere and login fails only in production. The password must be an SMTP key. Brevo's documentation stresses using an SMTP key and not an API key. - The platform blocks the connection. Users report that free Render web services time out on outbound SMTP while paid instances connect. We could not confirm the exact blocked ports from Render's documentation, so check Render's docs or ask Render support before you plan around a specific port.
A less common fourth cause: the from address is not a sender or domain you set up in Brevo.
Find your cause in the Render logs
Open your service in the Render dashboard, go to Logs, trigger the failing request again, and look for the exception class just above the 500.
| Exception in the log | Likely cause | Fix |
|---|---|---|
Net::OpenTimeout or execution expired | Connection blocked, or host unreachable | Fix 3 |
SocketError: getaddrinfo | Wrong or outdated hostname | Fix 1 |
Errno::ECONNREFUSED | Wrong port, or a blocked one | Fix 1 |
Net::SMTPAuthenticationError with 535 | Wrong login or key | Fix 2 |
Net::SMTPFatalError mentioning sender or domain | Sender not set up in Brevo | Fix 4 |
| No exception, no mail | Background job failing | Fix 5 |
Tip
Set raise_delivery_errors to true in production while you debug, and use deliver_now instead of deliver_later. Otherwise the error may never reach the request, and you will see a 200 with no mail.
Fix 1: use the current Brevo host and port
Port 587 with STARTTLS is the usual submission port for authenticated SMTP, so start there.
# config/environments/production.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: "yourapp.onrender.com", protocol: "https" }
config.action_mailer.smtp_settings = {
address: "smtp-relay.brevo.com",
port: 587,
user_name: ENV["BREVO_SMTP_LOGIN"],
password: ENV["BREVO_SMTP_KEY"],
authentication: :plain,
enable_starttls_auto: true
}
Then set the two variables:
- In the Render dashboard, open your service and go to Environment.
- Add
BREVO_SMTP_LOGINandBREVO_SMTP_KEY. - Save and redeploy; environment changes apply to a new deploy or restart.
If you try another port such as 465, the encryption setting has to match the port, and a mismatch fails even with correct credentials. Brevo's help center lists its supported ports. Our SSL/TLS for SMTP explainer covers how 587 and 465 differ.
Fix 2: use the SMTP login and SMTP key
This is the most common mistake after the hostname. Brevo's SMTP login and key are not your account password.
Depending on when your account was created, the SMTP login is either your Brevo account email or an automatically generated address like [ID]@smtp-brevo.com, and changing your account email does not change it. Steps:
- In Brevo, click Settings > SMTP & API, then open the SMTP tab.
- Copy the Login value into
BREVO_SMTP_LOGIN. - Click Generate a new SMTP key if you do not have one, and copy it right away. Newly created keys are not fully visible afterwards; only the last few digits are shown. Store it as
BREVO_SMTP_KEY. - Paste both into Render with no leading or trailing spaces or line breaks.
- Do not put the host name in the username field; Brevo's SMTP troubleshooting page lists that among the causes of authentication failures.
- Redeploy.
For the full field list, see Brevo's article on sending transactional emails with Brevo SMTP, and for key handling, Create and manage your SMTP keys.
Fix 3: get past a blocked SMTP connection on Render
If the log shows a timeout and your host, login and key are right, a platform-level block is the likely cause, and Brevo cannot help because the connection never leaves Render. Check Render's documentation for outbound SMTP restrictions on your instance type; we could not verify the current details from Render's own pages.
| Option | Cost | Code change | Notes |
|---|---|---|---|
| Upgrade the web service to a paid instance | Render paid plan | None | Same SMTP settings; confirm with Render that SMTP is open |
| Send through Brevo's HTTPS API | Your existing Brevo plan | Small delivery method | Uses port 443, no SMTP port needed |
| Try another SMTP port | None | Port setting | May fail again if the platform blocks SMTP in general |
I'd skip the port-hopping option. A platform that blocks SMTP on purpose may block the alternatives too, and a port that works today can stop working.
Send through Brevo's API over HTTPS
Brevo exposes a "Send a transactional email" call in its v3 API. The sketch below posts to https://api.brevo.com/v3/smtp/email with an api-key header; confirm the endpoint and field names against Brevo's API reference before you ship it. Create a v3 API key on Settings > SMTP & API, store it as BREVO_API_KEY on Render, and add a small delivery method so your existing mailers keep working:
# lib/brevo_api_delivery.rb
require "net/http"
require "json"
class BrevoApiDelivery
def initialize(settings)
@api_key = settings[:api_key]
end
def deliver!(mail)
uri = URI("https://api.brevo.com/v3/smtp/email")
html = mail.html_part ? mail.html_part.body.decoded : (mail.mime_type == "text/html" ? mail.body.decoded : nil)
text = mail.text_part ? mail.text_part.body.decoded : (mail.mime_type == "text/plain" ? mail.body.decoded : nil)
payload = {
sender: { email: mail.from.first },
to: mail.to.map { |address| { email: address } },
subject: mail.subject
}
payload[:htmlContent] = html if html
payload[:textContent] = text if text
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = 5
http.read_timeout = 10
request = Net::HTTP::Post.new(uri)
request["api-key"] = @api_key
request["content-type"] = "application/json"
request["accept"] = "application/json"
request.body = payload.to_json
response = http.request(request)
raise "Brevo API error #{response.code}: #{response.body}" unless response.is_a?(Net::HTTPSuccess)
end
end
# config/initializers/brevo_api_delivery.rb
require Rails.root.join("lib/brevo_api_delivery")
ActionMailer::Base.add_delivery_method :brevo_api, BrevoApiDelivery,
api_key: ENV["BREVO_API_KEY"]
# config/environments/production.rb
config.action_mailer.delivery_method = :brevo_api
This covers one sender, to recipients, and HTML or text bodies. It skips attachments, cc, bcc and reply-to, so add those if you use them.
Warning
Do not commit API or SMTP keys to your repository. Keep them in Render's Environment settings, and regenerate any key that has been pushed to a public repo.
Fix 4: set up the sender in Brevo
Whichever route you take, Brevo sends from senders or domains you have configured. If your mailer's from is something like noreply@yourapp.com and you never added it, the message can be rejected. Add and verify the sender in Brevo's senders and domains settings; labels move around, so search the dashboard if you do not see it.
For anything beyond testing, authenticate the domain too, so mail does not land in spam. Our SPF, DKIM and DMARC setup guide covers the records. Publish the DNS records Brevo gives you.
Fix 5: when nothing raises and no mail arrives
With deliver_later, the exception happens in a background job, not in the request, so the page can return 200 while mail fails. Check your job worker logs. With the async adapter, queued jobs are lost if the process restarts.
Then look at Brevo's transactional logs for the message. If it appears there with a status, the problem is downstream of Rails, such as recipient filtering. The email header analyzer helps read a delivered message's path and authentication results.
Checklist before you redeploy
- Host is
smtp-relay.brevo.comand port is587, or you moved to the API. BREVO_SMTP_LOGINis the value from the SMTP tab, not the host name.BREVO_SMTP_KEYis an SMTP key with no stray whitespace (orBREVO_API_KEYfor the API route).- All variables are set in Render's Environment and the service was redeployed.
- The
fromaddress is a sender you set up in Brevo. - Your Render instance allows outbound SMTP, or you send over HTTPS.
default_url_optionshas your real host, so mail links do not point at localhost.
If nothing works
Contact Render support if the timeout persists and you believe SMTP should be open on your plan. Contact Brevo support if Rails connects but authentication or sending is rejected. Include the exact exception text and timestamp from the Render logs, the host and port you use, the SMTP login (never the key), and what you already tried.
Subject: SMTP connection fails from my Rails app on Render
Hi, my Rails app on Render cannot send through Brevo SMTP.
Service: {your-service-name}
Host/port: smtp-relay.brevo.com:587
Exception in logs: {paste exact error, e.g. Net::OpenTimeout}
Timestamp (UTC): {time}
SMTP login (no key): {login}
Already tried: checked login/key, redeployed, set up sender.
Can you confirm whether outbound SMTP is allowed for this service/account?
Common questions
Is smtp.sendinblue.com still valid?
Do not rely on it. Brevo's current documentation names smtp-relay.brevo.com as the SMTP server, so use that.
Can I use my Brevo account password or API key as the SMTP password?
No. Use an SMTP key generated on the SMTP tab. Brevo says plainly to use an SMTP key and not an API key.
Which Brevo port should I use?
Start with 587 and STARTTLS. If your host blocks it, Brevo's help center lists the alternative ports, but a platform-wide SMTP block will not be fixed by changing ports.
Why does it work locally but not on Render?
Usually one of two things: your local network allows outbound SMTP while the Render service may not, or your credentials live in a local .env that never reached Render.
Explore: Email Deliverability
Related Articles
Brevo emails going to spam at Hotmail? Fix it before switching ESP
Switching ESP rarely fixes Hotmail spam or soft inbox placement from Brevo. SPF, DKIM, DMARC alignment, list quality and domain reputation travel with your domain. Check alignment in a real message header, test a clean engaged segment, read Postmaster Tools, and only then decide whether switching is worth it.
Brevo emails soft bouncing or stuck in processing at Gmail, Yahoo
If Brevo emails to Gmail and Yahoo soft bounce or sit "in processing," the usual causes are broken DMARC, a shared IP with poor reputation, mixed transactional and marketing traffic, or unengaged contacts. Fix DMARC first, separate the streams, suppress dead addresses, then ramp volume slowly.
Brevo form reCAPTCHA "invalid domain": add sibforms.com
A Brevo form that shows "reCaptcha invalid domain" usually means your reCAPTCHA key doesn't list sibforms.com, the domain Brevo serves its forms from. Open the key in the Google reCAPTCHA console, add sibforms.com under domains, save, and reload the form. A new key fails the same way until the domain is added.
Brevo SMTP "wrong version number" on smtp-relay.brevo.com:587
Port 587 on smtp-relay.brevo.com uses STARTTLS, so connecting with implicit SSL (an ssl:// prefix or an SSL checkbox) fails with "wrong version number". Switch the encryption setting to TLS or STARTTLS and use the smtp-relay.brevo.com host. If "certificate verify failed" follows, update your server's CA bundle.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free