I am using Rails 2.3.11. I created a UserMailer with following methods:
def rsvp_created(user, rsvp, pdf_file)
setup_email(user)
content_type "multipart/mixed"
@subject << "Your RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
attachment :content_type => 'application/pdf',
:body => File.read(pdf_file),
:filename => "#{rsvp.confirmation_number}.pdf"
end
def rsvp_cancelled(user, rsvp)
setup_email(user)
content_type "text/html"
@subject << "Cancelled RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
@body[:holiday_url] = APP_CONFIG['site_url'] + holiday_path(rsvp.ticket.holiday)
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = APP_CONFIG['admin_email']
@subject = "[#{APP_CONFIG['site_name']}] "
@sent_on = Time.now
@body[:user] = user
end
The rsvp_cancelled works fine and sends email properly. But the rsvp_created email, which has an attachment, doesn’t work properly. It sends the email with the attached file but doesn’t render any text. Any one faced this issue before or know how I can resolve it?
Thanks
With Rails 2.x, for some reason or the other you need to define all the parts for the HTML to appear.
Thankfully it appears this is not the case in Rails 3.x.