Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using this gem with Rails should be documented #135

Open
skalee opened this issue Apr 19, 2019 · 1 comment
Open

Using this gem with Rails should be documented #135

skalee opened this issue Apr 19, 2019 · 1 comment

Comments

@skalee
Copy link
Contributor

skalee commented Apr 19, 2019

This gem works with Rails nicely, however it requires a small additional step, which isn't obvious. A short README section is required at minimum.

For reference, the easiest way to use EnMail in Rails is to register an interceptor. Voilà:

class CryptoInterceptor
  def self.delivering_email(message)
    adapter = EnMail::Adapters::RNP
    EnMail.protect :sign, message, adapter: adapter
  end
end

ActionMailer::Base.register_interceptor(CryptoInterceptor)
@skalee skalee changed the title F Using this gem with Rails should be documented Apr 19, 2019
@skalee
Copy link
Contributor Author

skalee commented Apr 19, 2019

Also for reference, some full example which works as expected if executed in EnMail's root directory, provided that keys have been generated with rake pgp_keys:generate:

$LOAD_PATH.unshift File.expand_path("lib", __dir__)
$PGP_HOME = File.expand_path("tmp/pgp_home", __dir__)

require "action_mailer"
require "enmail"

class ExampleMailer < ActionMailer::Base
  def carthage
    mail(
      to: "Roman Senate <senate@example.test>",
      from: "Cato Elder <cato.elder@example.test>",
      subject: "About Carthage",
      body: "Must be destroyed!",
    )
  end
end

class CryptoInterceptor
  def self.delivering_email(message)
    adapter = EnMail::Adapters::RNP
    EnMail.protect :sign, message, adapter: adapter, homedir: $PGP_HOME
  end
end

ActionMailer::Base.delivery_method = :test
ActionMailer::Base.register_interceptor(CryptoInterceptor)

ExampleMailer.carthage.deliver_now

puts ActionMailer::Base.deliveries.first.encoded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant