Open skalee opened 5 years ago
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
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à: