Skip to content

Fix NameError in Mailgun and Mailjet on Ruby 3.4 - #57

Merged
eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix-base64-mailgun-mailjet
Aug 31, 2026
Merged

eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix-base64-mailgun-mailjet

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Mailgun#default_headers and Mailjet#default_headers both call Base64.strict_encode64 without requiring base64. Ruby 3.4 moved base64 out of the default gems, so the constant is undefined and every delivery through either provider raises NameError:

NameError: uninitialized constant Courrier::Email::Providers::Mailgun::Base64
    lib/courrier/email/providers/mailgun.rb:36:in 'default_headers'

The gemspec already sets required_ruby_version = ">= 3.4.0", so this affects every supported Ruby version.

The fix

Encode with Array#pack("m0") rather than adding require "base64".

strict_encode64 is implemented on top of the same pack directive, and the output is byte-identical (verified across ASCII, UTF-8, empty string, and long input). Using it directly avoids adding a bundled-gem dependency to the gemspec for two lines of code.

Tests

Adds mailgun_test.rb and mailjet_test.rb — 11 tests covering body formatting, endpoint construction, the domain requirement, reply_to omission, and the auth headers that reproduce the bug.

Both auth tests fail on main with the reported NameError and pass with this change. Full suite: 111 runs, 202 assertions, 0 failures, 0 errors. standardrb reports no offenses.

The expected header values are written as base64 literals rather than computed with pack, so the tests do not validate the implementation against itself.

Fixes #56

Both providers called `Base64.strict_encode64` in `default_headers`
without requiring `base64`. Ruby 3.4 moved `base64` out of the default
gems, so the constant is undefined and every delivery raises NameError.

Since the gemspec already requires Ruby >= 3.4, this affects every
supported version.

Encode with `Array#pack("m0")` instead of requiring `base64`. It is what
`strict_encode64` uses internally and produces identical output, so the
fix adds no new dependency to the gemspec.

Adds test coverage for both providers, including the authentication
headers that reproduce the bug.

Fixes Rails-Designer#56
@eelcoj
eelcoj force-pushed the fix-base64-mailgun-mailjet branch from 0cd30ea to 9e362b0 Compare August 31, 2026 11:18
@eelcoj
eelcoj merged commit f70ba59 into Rails-Designer:main Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mailgun and Mailjet raise NameError on Ruby 3.4 (Base64 not required)

2 participants