What is the correct syntax for sending emails using actionmailer that includes some PDF file attachments? I use Gmail for SMTP, with a TLS plugin. Here is what I have so far (and also tried the options):
**lead_mailer.rb:**
def auto_response(lead)
recipients lead.email
subject "Information"
body :recipient => lead.first_name
from "me@mydomain.com"
attachment "application/pdf" do |a|
a.body = File.read(RAILS_ROOT + "/public/files/Datasheet.pdf")
end
attachment "application/pdf" do |a|
a.body = File.read(RAILS_ROOT + "/public/files/OtherSheet.pdf")
end
end
**lead_observer.rb:**
class LeadObserver < ActiveRecord::Observer
def after_save(lead)
mail = LeadMailer.create_auto_response(lead)
LeadMailer.deliver(mail)
end
end
The problem is that it sends attachments, but they are displayed as “no name”, although when they are opened, they are displayed correctly. However, the body of the letter does not appear at all. I am sure that I am doing something simple, wrong.
source
share