Created
August 16, 2011 01:30
-
-
Save cmaujean/1148267 to your computer and use it in GitHub Desktop.
Sending html email in spree w/pdf attachment:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%# app/views/order_mailer/confirm.html.erb %> | |
<html> | |
<head> | |
<style type="text/css"> | |
* { | |
font-size: 12px; | |
} | |
h2 {color: #00704a; font-family:Arial, Helvetica, sans-serif; font-size: 16px;} | |
.yellow_tr { | |
background-color: #f9f8cc; | |
border-bottom: #f9f8cc 1px solid; | |
} | |
.green_tr { | |
background-color: #d1e4dc; | |
border-bottom: #d1e4dc 1px solid; | |
} | |
td.white { | |
background-color: #ffffff; | |
} | |
</style> | |
</head> | |
<body> | |
Dear <%= @order.bill_address.full_name %>,<br /><br /> | |
<p> | |
Thank you for your purchase! Attached is your order confirmation, you may wish to print and retain it for your records. | |
</p> | |
<p> | |
<strong>Please do not reply to this email.</strong> If you need to contact us, you can email us at: <a href="mailto:[email protected]">[email protected]</a> or call us at: <strong>(800) 555-1212</strong> Monday to Saturday 8am to 5pm (Atlantic Time). | |
</p> | |
<p> | |
Thank you for your business! | |
</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/mailers/order_mailer.rb | |
require 'rtw_mail' | |
class OrderMailer < ActionMailer::Base | |
helper "spree/base" | |
include RtwMail | |
def confirm_email(order, resend = false) | |
rtw_send_mail(order, "Confirmation", "confirm", resend) | |
end | |
def shipped_email(order, resend = false) | |
rtw_send_mail(order, "Delivery", "shipped", resend) | |
end | |
def cancel_email(order, resend = false) | |
rtw_send_mail(order, "Cancel", "canceled", resend) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/rtw_mail.rb | |
module RtwMail | |
def order_bcc | |
# n/a to the context of this gist | |
end | |
def rtw_send_mail(order, subj, type, resend) | |
@order = order | |
# generate a pdf invoice and add it to the email | |
attachments["#{@order.number}.pdf"] = { 'Content-type' => 'application/pdf', :content => OrderInvoice.new.to_pdf(order, true) } | |
mail(:subject => (resend ? "[RESEND] " : "") + Spree::Config[:site_name] + ' ' + 'Order ' + subj + ' #' + order.number, | |
:from => Spree::Config[:order_from], | |
:recipients => order.email, | |
:bcc => order_bcc | |
) do |format| | |
format.html { render_message(type, :order => order) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment