Temp mail
in Ruby.
Disposable email for Ruby, driven by plain net/http.
require "net/http"
require "json"
uri = URI("https://evilmail.pro/api/temp-email")
req = Net::HTTP::Post.new(uri)
req["X-API-Key"] = ENV.fetch("EVILMAIL_KEY")
req["Content-Type"] = "application/json"
req.body = { ttlMinutes: 30 }.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(req)
end
data = JSON.parse(res.body).fetch("data")
puts "Inbox: #{data['email']}"
puts "Token: #{data['sessionToken']}"Wiring up a Ruby temp mail inbox lets you automate email verification without a real mailbox, a browser, or manual copy-pasting of OTP codes. EvilMail exposes a small HTTP API you can drive with Ruby's standard net/http library: create a disposable inbox, poll it until the message lands, then regex the confirmation code straight out of the body. It's built for developers who need temporary email in Ruby inside test suites, CI pipelines, and signup or OTP flows — no third-party gems, no fake SDKs, just plain requests and JSON.
Why use temp mail in Ruby
End-to-end signup tests
Register a fake user against a live temp mail address and assert the welcome or confirmation email actually arrives. No shared team inbox to pollute or clean up.
OTP & 2FA verification testing
Trigger a login or password reset, poll the inbox, and pull the 6-digit code with a single regex. Your Ruby email verification testing runs fully unattended.
CI/CD pipelines
Because it's just net/http and an API key, disposable email in Ruby works the same on your laptop and in GitHub Actions or GitLab CI — no SMTP server or browser automation to maintain.
Scraping activation links
Grab the full text or HTML of a message and extract magic links, invite tokens, or activation URLs to complete multi-step onboarding flows programmatically.
The flow — Ruby temp mail in 3 calls
Create a disposable inbox
require "net/http"
require "json"
# Create a temp inbox that self-destructs after 30 minutes.
def create_inbox
uri = URI("https://evilmail.pro/api/temp-email")
req = Net::HTTP::Post.new(uri)
req["X-API-Key"] = ENV.fetch("EVILMAIL_KEY")
req["Content-Type"] = "application/json"
req.body = { ttlMinutes: 30 }.to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(req)
end
data = JSON.parse(res.body).fetch("data")
[data["email"], data["sessionToken"]]
end
email, token = create_inbox
puts "Waiting for mail at #{email}"Poll until the email arrives
require "net/http"
require "json"
# Poll the inbox until a message lands (or we give up).
def wait_for_message(token, tries: 20, delay: 3)
uri = URI("https://evilmail.pro/api/temp-email/#{token}")
tries.times do
req = Net::HTTP::Get.new(uri)
req["X-API-Key"] = ENV.fetch("EVILMAIL_KEY")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(req)
end
msgs = JSON.parse(res.body).dig("data", "messages") || []
return msgs.first unless msgs.empty?
sleep delay # wait before the next attempt
end
raise "No message arrived in time"
end
message = wait_for_message(token)
puts "Got: #{message['subject']} (uid #{message['uid']})"Read the message & extract the code
require "net/http"
require "json"
# Fetch the full body and pull out a 6-digit OTP.
def extract_code(uid, token)
uri = URI("https://evilmail.pro/api/message/#{uid}?token=#{token}")
req = Net::HTTP::Get.new(uri)
req["X-API-Key"] = ENV.fetch("EVILMAIL_KEY")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
http.request(req)
end
body = JSON.parse(res.body).fetch("data")
# First standalone 6-digit number, from text then html.
body["text"].to_s[/\b(\d{6})\b/, 1] ||
body["html"].to_s[/\b(\d{6})\b/, 1]
end
otp = extract_code(message["uid"], token)
puts "Verification code: #{otp}"Ruby temp mail — FAQ
Q1How do I get a temp mail address in Ruby?−
Send a POST request to https://evilmail.pro/api/temp-email with your X-API-Key header and a JSON body like {"ttlMinutes": 30}. The response's data.email is your disposable address and data.sessionToken is the handle you use to poll for and read incoming mail. The hero snippet above does exactly this in about a dozen lines of net/http.
Q2Can I use this for automated testing?+
Yes — that's the primary use case. Because it's plain HTTP with no browser or SMTP dependency, it drops cleanly into RSpec, Minitest, or any CI job. Create an inbox, trigger the email under test, poll until it arrives, and assert on the subject, body, or extracted code. It works identically on a laptop and in GitHub Actions or GitLab CI.
Q3How do I extract the OTP?+
Read the message via GET /api/message/{uid}?token={sessionToken}, then run a regex over data.text (or data.html). A standard 6-digit one-time code matches /\b(\d{6})\b/ — use body["text"].to_s[/\b(\d{6})\b/, 1] to capture the first match. For magic links or tokens, swap in a pattern that matches your URL or token format.
Q4Do I need an API key / rate limits?+
Yes, every request needs an X-API-Key header — read it from an environment variable such as ENV.fetch("EVILMAIL_KEY") and never hard-code it in source. Requests are rate limited per key; the polling example uses a 3-second interval, which stays comfortably within limits for testing and OTP flows.
Q5How long does the inbox live?+
You control the lifetime with ttlMinutes when you create the inbox — the example uses 30 minutes. Once the TTL expires the address and its messages are discarded automatically, so there's nothing to clean up. For longer-running suites, request a larger TTL or simply create a fresh inbox per test case.
Temp mail in other languages
One API key. Disposable inboxes at scale.
Create unlimited throwaway addresses, poll them over HTTP, and pull verification codes straight into your tests and CI. Free to start; custom domains and higher limits on paid plans.

