Having some problem with sending email with attachment: I am able to send an email without attachment via gmail server. However, when i tried to send an image attachment, it is corrupted at the recipient mailbox; coz the mail received: (1) Has the attachment, but not able to open the image file. (2) The attachment image file size is much smaller. (3) The message in the email body is missing (which was there if i send without the attachment portion). Below is the part of my model code: ============== models/event_mailer.rb ====================== class EventMailer < ActionMailer::Base def email_friend(recipient, sender_name, event) subject 'Check out this great event' from 'email@example.com' recipients recipient content_type 'text/html' body "sender_name" => sender_name, "event" => event attachment :context_type => 'image/png', :body => File.read('public/images/rails.png') end end BTW, i am using rails 2.1.2, ruby 1.8.6 What did i miss out? Any suggestions will be greatly appreciated. Thanks!
on 2008-11-22 11:32
on 2008-11-23 09:32
Found the solutions: 1) For the error where the email body was not received by the recipient, it was because of the naming of the view file has the wrong extension. I had to changed it to "email_friend.erb", instead of "email_friend.html.erb. 2) As for the corrupted image file, it was because it was not opened as a binary file. I learn of this from: http://www.ruby-forum.com/topic/85591#156951