Skip to content

Conversation

andrii-baran-nfgp
Copy link

@andrii-baran-nfgp andrii-baran-nfgp commented Jan 24, 2024

Fixes

A short description of what this PR does.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@andrii-baran-nfgp andrii-baran-nfgp changed the title Added reply_to_list support feat: Added reply_to_list support Jan 24, 2024
@andrii-baran-nfgp andrii-baran-nfgp changed the title feat: Added reply_to_list support feat: Added mail.reply_to_list support Jan 24, 2024
@andrii-baran-nfgp andrii-baran-nfgp marked this pull request as draft January 24, 2024 09:40
@andrii-baran-nfgp andrii-baran-nfgp marked this pull request as ready for review November 21, 2024 15:31
@beld2107
Copy link

Hi,

Any chance this functionality can be added in the next version of the Gem?

@eterry1388
Copy link

We need this functionality as well. The gem is out of date from the docs.

@beld2107
Copy link

beld2107 commented Sep 10, 2025

For anyone else, in the meantime I just monkey patched the class:

In Rails:
config/initializers/sendgrid_reply_to_list_patch.rb

# Add support for #reply_to_list, until they add support on their end
if SendGrid::Mail.instance_methods.include?(:reply_to_list)
  warn "SendGrid::Mail added support for #reply_to_list -> please remove #{__FILE__}"
  exit 1 # rubocop:disable Rails/Exit
else
  module SendGrid
    class Mail
      attr_accessor :reply_to_list

      alias_method :original_to_json, :to_json

      def to_json(*)
        result = original_to_json

        if @reply_to_list.present?
          result['reply_to_list'] = @reply_to_list.map { |reply_to|
            if reply_to.respond_to?(:to_json)
              JSON.parse(reply_to.to_json)
            else
              reply_to
            end
          }

          result.delete('reply_to') if result.key?('reply_to')
        end

        JSON.generate(result)
      end
    end
  end
end

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.

3 participants