--- type: Guide title: Rails integration (euromailing-rails) description: The euromailing-rails gem — ActionMailer delivery method for transactional mail, contact/list client, Syncable concern for mirroring users, ActionMailbox inbound. resource: https://github.com/rogerheykoop/euromailing-rails tags: [rails, gem, actionmailer, sync] timestamp: 2026-07-06T00:00:00Z --- # Rails integration: the euromailing-rails gem Source & full README: https://github.com/rogerheykoop/euromailing-rails (MIT, Ruby ≥ 3.1, no runtime dependencies beyond what Rails ships). ```ruby # Gemfile gem "euromailing-rails", github: "rogerheykoop/euromailing-rails" ``` ```ruby # config/initializers/euromailing.rb Rails.application.config.euromailing.api_key = Rails.application.credentials.dig(:euromailing, :api_key) ``` ## 1. Transactional mail through ActionMailer ```ruby # config/environments/production.rb config.action_mailer.delivery_method = :euromailing ``` Existing mailers work unchanged. The `from:` must be on the API key's bound sending domain. One recipient per message; prefer `deliver_later` (the API allows 60 requests/minute per key). ## 2. Contacts & lists ```ruby client = Euromailing.client client.upsert_contact(email: "jan@example.com", first_name: "Jan") client.delete_contact(email: "jan@example.com") client.subscribe(list_id: "LIST-UUID", email: "jan@example.com") client.unsubscribe(list_id: "LIST-UUID", email: "jan@example.com") ``` Errors raise `Euromailing::ApiError` with `#status` and `#code` (codes documented in [the API reference](../api/index.md)). ## 3. User sync ```ruby class User < ApplicationRecord include Euromailing::Syncable euromailing_sync lists: ["NEWSLETTER-LIST-UUID"], if: ->(u) { u.newsletter? } def euromailing_contact_attributes { email: email, first_name: first_name, last_name: last_name, custom_fields: { plan: plan } } end end ``` Creates/updates upsert the contact and subscribe the configured lists; destroys delete it — all via `Euromailing::SyncJob` (ActiveJob, retries with backoff, 404-on-delete counts as success). ## 4. Inbound mail See [Inbound to ActionMailbox](inbound-actionmailbox.md).