spree order confirmation email - ruby-on-rails

I need to modify the emails which go to the customers in the spree app.
At the moment a very ordinary form goes to the customer email.
I am unable to find the code where I can modify that email and add custom template.
Anyone having worked on this point earlier?

The mail templates are in core/app/mailers/spree and the mail that goes out after orders should be core/app/mailers/spree/order_mailer.rb.

In app/mailers/spree you need to create a file called order_mailer_decorator.rb. In this file you add:
Spree::OrderMailer.class_eval do
def confirm_email(order, resend = false)
your code
end
end
In views/spree/order_mailer in a file confirm_email.html.erb you need to write your code.

Related

Send email to all users from rails admin

I have added rails_admin in my application. Now I need to add an additional feature, that is send email to all users from the rails application. How can I add a new view with in rails_admin. Currently I have added a new static menu in rails_admin.rb
config.navigation_static_links = {
'Compose' => '/admin/email'
}
But it is opened in a new tab as a seperate view with no side bar, footer, header etc..
I want to add this feature like dashboard. Please give some useful hints for my issue. Thanks in advance
probably you will need to create what RailsAdmin define as Action for your Admin role and make sure you manage correctly the admin authentication with Devise
You can implement a method that sends email with ActionMailer, I am quoting the solution from Hitham S.AlQadheeb from the following post. Go check his post for more info.
For each call to the mailer method one email is sent in scheduled worker
def calling_method
#users.each do |user|
send_digest(user.email, user.name)
end
end
in user mailer
def send_digest(user_email, user_name)
mail(to: user_email, subject: user_name)
end
You need to create a custom action
https://github.com/sferik/rails_admin/wiki/Custom-action
Based on the dashboard
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/dashboard.rb
And if you want a link to it visible at all times, you will need to override the existing navigation partial on your project.
https://github.com/sferik/rails_admin/blob/master/app/views/layouts/rails_admin/_navigation.html.haml

Can anyone show me how to make "Mailboxer"'s controller, model, view, and routes?

First of all, thanks in adavance.
This might be so noob question.
I already did setup devise and mailboxer. devise works completely fine!
Then "username" column is added to Users table, and I configured just like this
/config/initializers/mailboxer.rb
#Configures the methods needed by mailboxer
config.email_method = :email
config.name_method = :username
Now I'm totally stucked!! I don't know how to make the rest for simple message system.
What I want is these message function listed below
index(index/received or index/sent)... you can see the list of messages received(from/to, subjectes, and received date are only shown)
show...you can see whole body of the message.
new... message create form, as an option, you can choose 'reply' from "show" page. in this case body text field already includes messages quotes.
Can someone make very simple example for me?
I can pay up to $50 for it via paypal!
I think I need to make
"messages_controller"
"message" model if you needed with mailboxer gem
"view/messages/index", "view/messages/show", "view/messages/new"
"routes" has to be modified.
Thanks
I assume you've resolved your issues by now, but for future reference, a sample app featuring the mailboxer gem is:
https://github.com/RKushnir/mailboxer-app
(not mine, but helpful to get up and going)

Checking for new emails from within Rails

Within Rails, how can I listen for new mail coming into the boxes of certain accounts. I want to implement a simple "post-by-email" service, which gets the new content of the email and makes a blog post or sth.
You could try this gem.
I wrote a post explaining some of the options. A later post also covered my way of testing these options. The mail gem is great for parsing. You just have to decide the best option for you to optain the messages.
http://steve.dynedge.co.uk/2010/09/07/incoming-email-in-rails-3-choosing-the-right-approach/
I use this code to parse my emails.
class Receiver < ActionMailer::Base
def self.parse(email)
reply_separator = /(.*?)\s?== ADD YOUR REPLY ABOVE THIS LINE ==/m
comment_text = reply_separator.match(email.body.to_s)
# ...
end
end
The email object here is just a Mail::Message object which I get from using the gmail gem to read an inbox. If you're not using GMail then you should be able to use plain ol' vanilla Mail gem to connect to the mail server and then get the Mail::Message objects that way.

Rails: Email a pdf generated with prawn to an email sent by ActionMailer?

I have an ecommerce app. I'm using Prawn to generate pdf invoices of orders. I'm using a standard Prawn setup. In views/admin/orders, I have a file called show.pdf.prawn. When the seller is viewing an order in his admin section, he clicks a link that opens the pdf version of the orders/show view. This all works perfectly.
Now, the tricky part. When an order is completed, I send an email to the seller. What I'd like to do is attach the pdf invoice version of orders/show to that email. Is it possible to do this? The documentation on email attachments is pretty limited and I haven't been able to find resources that go through the workflow that I'm describing.
Any guidance is appreciated.
Sending an attachment with an email is fairly easy with ActionMailer:
class InvoiceMailer < ActionMailer::Base
def email_with_attachment(pdf_invoice)
.
.
.
attachment "application/pdf" do |a|
a.filename = "some_invoice.pdf"
a.body = pdf_invoice
end
end
end
One problem you might have with this is generating the pdf file outside of the prawnto method (when using the prawnto plugin)-
If this is is the case I strongly recommend you to use this approach instead.
I had the same problem, i managed to do it by generating the pdf from a model, much easier than evaluating the template. I replied with the answer here :
Save a Prawn PDF as a Paperclip attachment?

ActionMailer- access Mail::Message content, or manually initialize view in controller?

I've got a form where an internal user can request that informational materials be sent to a client. When the form is submitted, it sends an email to the person in charge of physically mailing the materials to the client.
Now, I want to capture the content of the email so I can add a note to the client's show page, and I'm unsure how to go about it.
One option I've looked at is to use an after_filter in the MaterialsRequestMailer, but calling message.body returns a large string with way more text than I need and I want to avoid adding a bunch of parsing logic to get the message content.
Basically, I want what is generated by the views/materials_request_mailer/send_request_notification.text.erb template. I've looked through http://www.rubydoc.info/github/mikel/mail/Mail/Message and can't find a method to return just the rendered template content. Is there a way to do that?
If not, is there a way to manually initialize a View in the controller, where I already have the instance variables I'm passing to the mailer? That doesn't seem to be an ideal solution, because I'm using DelayedJob, and the code for adding the note would be run before the email is actually sent. Also, due to DelayedJob, it appears that I can't directly access the mail object from within the controller (if I do mail = MaterialsRequestMailer.delay.send_request_notification(...) it assigns an instance of Delayed::Backend::ActiveRecord::Job to mail).
Found a solution that works- message.text_part.body.raw_source is what I was looking for. (credit to this answer: https://stackoverflow.com/a/15257098/2599738)
class MaterialsRequestMailer < ActionMailer::Base
include AbstractController::Callbacks
after_filter :add_note_to_client
def send_request_notification(client, ...)
#client = client
...
end
def add_note_to_client
mail_text = message.text_part.body.raw_source
#client.add_account_note(mail_text)
end
end

Resources