I found a solution to send ActionMailer messages with attachments.
The documentation in the wiki is inaccurate, you can''t just add an
attachment to an existing TMail object that has been created by
ActionMailer. It will not create the proper mime structure.
This is just rough code and needs to be cleaned up, but it works for
sending multipart messages with attachments. You can easily add both
plain/text and html.text parts, as well as loop through a list of
attachments.
The stumbling block in ActionMailer is that it creates a plain/text e-
mail message. Not a multipart/mixed or alternative message structure
to start with.
mime = Mailer.create_message() # Generate initial message
mail = TMail::Mail.new # Create a new mail object
mail.parts << mime # Insert plain or html text part
mail.parts << attachment # add attachment
# Copy required headers
mail.to = @mime.to
mail.from = @mime.from
mail.subject = @mime.subject
# Deliver message
Mailer.deliver(mail)
To create an attachment I found this worked fairly well. Although you
must encode the attachment content or TMail _may_ ignore it.
attachment = TMail::Mail.new
attachment.body = Base64.encode64(content)
attachment.set_content_type(file.content_type, "name" => file_name)
attachment[''Content-Transfer-Encoding''] = "base64"
attachment[''Content-Disposition''] = "attachment;
filename=\"#
{file_name}\""
This need a lot of work still. But it works.
--
Lon Baker
Speedymac LLC
http://www.speedymac.com
AIM: spdemac
Skype: spdemac