Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send signed emails from ActionMailer in Rails 3?

Using Rails 3 I want to use an X.509 certificate to sign parts of emails. There is a currently existing answer for Rails 2 at How do I send signed emails from ActionMailer? but it doesn't work on Rails 3.

Is it possible to sign emails via ActionMailer in Rails 3? If that is not possible, is it possible to sign emails via sendmail after creating by ActionMailer?

like image 518
petRUShka Avatar asked Jun 21 '11 16:06

petRUShka


People also ask

What is Action_ Mailer in Rails?

Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.

How do you send mail in Ruby?

To send the mail you use Net::SMTP to connect to the SMTP server on the local machine and then use the send_message method along with the message, the from address, and the destination address as parameters (even though the from and to addresses are within the e-mail itself, these aren't always used to route mail).

How do I Preview Mailer in Rails?

rails generates a mail preview if you use rails g mailer CustomMailer . You will get a file CustomMailerPreview inside spec/mailers/previews folder. Here you can write your method that will call the mailer and it'll generate a preview.


1 Answers

perhaps it's not the best answer, however here's what I'd do:

  • try to install that plugin (even if it's for rails 2.0.x)

  • tests and fix code until I get the result

looking at the code, turns out that the core file is:

https://github.com/penso/actionmailer_x509/blob/master/lib/actionmailer_x509.rb

which exposes a bunch of methods for mailer DSL:

  • x509_sign true # or false
  • x509_cert "path/to/cert"
  • x509_key "path/to/key"
  • x509_passphrase "passphrase"

so you could grab that file, and put it under $APP/lib, then write some test to check it's working.

A.

like image 140
Andrea Pavoni Avatar answered Oct 05 '22 23:10

Andrea Pavoni