How to Use Notify with Ruby
Send email with Ruby and Net::HTTP — no gems required.
Send email from Ruby using the standard library — no gems required.
Prerequisites
- API key — authenticate every request with the
x-api-keyheader - Verified domain (optional) — required for production sends from a custom
fromaddress
Send an email
require 'net/http'
require 'json'
require 'uri'
uri = URI('https://notify.cx/api/public/v1/email/send')
payload = {
to: 'user@example.com',
subject: 'Welcome aboard!',
message: '<h1>Welcome!</h1><p>Thanks for joining us.</p>'
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['x-api-key'] = ENV.fetch('NOTIFY_API_KEY')
request.body = JSON.generate(payload)
response = http.request(request)
puts response.body
API response:
{
"success": true,
"data": {
"messageId": "01000194b1dd1c04-b51e7343-6808-4a68-b2af-845feae57f8b-000000"
}
}
Plain text message
Use a plain string in message when you do not need HTML:
payload = {
to: 'user@example.com',
subject: 'Welcome aboard!',
message: 'Thanks for joining us!'
}
See Sending Emails for what gets delivered for each format.