Hi,
I’m having issues with getting a consistent result with the emails I am sending using Actionmailer.
Problem: Emails that I send with plain text, rich text, and attachments do not display the same results across GMail, Yahoo, Outlook and Thunderbird.
Scenario:
I am sending an email with text/plain, text/html, and 2 attachments using the code below, and I’ve specified the content_type. GMail receives and displays the email perfectly but in outlook, none of the attachments are displayed, and in thunderbird, the last attachment is displayed, and in yahoo, none of the attachments display. I’ve followed many tutorials including the guide in the actionmailer main doc.
this is in my mailer
Simplified Version:
def ticket_email(options)
msg = options[:ticket_id] ? "#{options[:message]}<br /><br
/>
Please leave the [Ref: ##{options[:ticket_id]}] in
your subject when replying, Thank you." : options[:message]
subject "subject"
recipients options[:recipients]||''
from options[:from]||''
cc options[:cc]||""
bcc options[:bcc]||""
content_type "multipart/alternative"
part :content_type => "text/plain", :body => render_message("ticket_email.text.plain.haml", :message => msg)
part :content_type => "text/html", :body => render_message("ticket_email.text.html.haml", :message => msg)
attachment :content_type => f.content_type, :body => contents, :filename => f.original_filename
end
Full Version (in case you wanted to take a look at it)
def ticket_email(options)
msg = options[:ticket_id] ? "#{options[:message]}<br /><br /><br />Please leave the [Ref: ##{options[:ticket_id]}] in your subject when replying, Thank you." : options[:message] subject options[:subject]||'No Subject' recipients options[:recipients]||'' from options[:from]||'' cc options[:cc]||"" bcc options[:bcc]||"" content_type "multipart/alternative" part :content_type => "text/plain", :body => render_message("ticket_email.text.plain.haml", :message => msg) part :content_type => "text/html", :body => render_message("ticket_email.text.html.haml", :message => msg) unless options[:file].nil? or options[:file].empty? options[:file].each do |f| unless f=='' if !f.path.nil? and !f.path.empty? contents = File.read(f.path) else contents = f.read end attachment :content_type => f.content_type, :body => contents, :filename => f.original_filename end end end
end Any help would be great, I have been searching for a solution for a while now.
Thanks, Matt