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

Send email button #14

Merged
merged 1 commit into from Jul 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/rails_email_preview/emails_controller.rb
Expand Up @@ -49,6 +49,19 @@ def show_raw
end
end

def test_deliver
I18n.with_locale @email_locale do
mail = @preview_class.new.send(params[:mail_action])
delivery_handler = RailsEmailPreview::DeliveryHandler.new(mail, to: params[:recepient_email], cc: nil, bcc: nil)
delivery_handler.mail.deliver
begin
redirect_to :back
rescue ActionController::RedirectBackError
redirect_to rep_root_url
end
end
end

protected

def set_email_preview_locale
Expand Down
6 changes: 6 additions & 0 deletions app/views/rails_email_preview/emails/_options.html.slim
Expand Up @@ -6,3 +6,9 @@
- I18n.available_locales.each do |locale|
a.btn href=rails_email_preview.rep_email_url(params.merge(part_type: @part_type, email_locale: locale)) class=('active' if @email_locale == locale.to_s)
= locale
br
br
= form_tag rails_email_preview.rep_test_deliver_url, method: :post do
= hidden_field_tag :email_locale, @email_locale
= text_field_tag :recepient_email, @mail.to.first
= submit_tag "Send Email", class: "btn btn-default"
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -3,6 +3,7 @@

get 'raw/:mail_class/:mail_action' => 'emails#show_raw', as: :rep_raw_email
get ':mail_class/:mail_action' => 'emails#show', as: :rep_email
post 'test_deliver/:mail_class/:mail_action' => 'emails#test_deliver', as: :rep_test_deliver

# define alias for the root url as part of stable api
get '/' => 'emails#index', as: :rep_root
Expand Down
1 change: 1 addition & 0 deletions lib/rails_email_preview.rb
Expand Up @@ -2,6 +2,7 @@
require 'rails_email_preview/engine'
require 'rails_email_preview/main_app_route_delegator'
require 'rails_email_preview/version'
require 'rails_email_preview/delivery_handler'

require 'slim'
require 'slim-rails'
Expand Down
15 changes: 15 additions & 0 deletions lib/rails_email_preview/delivery_handler.rb
@@ -0,0 +1,15 @@
module RailsEmailPreview
class DeliveryHandler
def initialize(mail, headers)
@mail = mail
@mail.headers(headers)
@mail.delivery_handler = self
end

attr_accessor :mail

def deliver_mail(mail)
yield
end
end
end