Skip to content

Commit

Permalink
Resolves body not displaying when attachment sent
Browse files Browse the repository at this point in the history
This commit places the message body in a separate MIME multipart message
part so that it will display when an attachment is sent. Also allows for
a :content_type option for the message body that can be set without
affecting the attachment.
  • Loading branch information
Nickolas Means committed Sep 26, 2009
1 parent 2cc3adf commit 72f2150
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lib/pony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@ def self.build_tmail(options)
mail.to = options[:to]
mail.from = options[:from] || 'pony@unknown'
mail.subject = options[:subject]
mail.body = options[:body] || ""
(options[:attachments] || []).each do |name, body|
attachment = TMail::Mail.new
attachment.transfer_encoding = "base64"
attachment.body = Base64.encode64(body)
# attachment.set_content_type # TODO: if necessary
attachment.set_content_disposition "attachment", "filename" => name
mail.parts.push attachment
end
if options[:attachments]
# If message has attachment, then body must be sent as a message part
# or it will not be interpreted correctly by client.
body = TMail::Mail.new
body.body = options[:body]
body.content_type = options[:content_type] || "text/plain"
mail.parts.push body
(options[:attachments] || []).each do |name, body|
attachment = TMail::Mail.new
attachment.transfer_encoding = "base64"
attachment.body = Base64.encode64(body)
# attachment.set_content_type # TODO: if necessary
attachment.set_content_disposition "attachment", "filename" => name
mail.parts.push attachment
end
else
mail.content_type = options[:content_type] || "text/plain"
mail.body = options[:body] || ""
end
puts mail
mail
end

Expand Down

0 comments on commit 72f2150

Please sign in to comment.