On 18/05/2005, at 5:06 PM, Lon Baker wrote:
> Does anyone have a working example of sending an ActionMailer with an
> attachment?
not a lot of help, but I had a working system (i was including a logo
image in an email). i cant recall exactly, but it went something like
this:
instead of using a deliver_* method, use create_*, which will return a
TMail::Mail[1] object, then you want to play around with Mail#parts.
playing in the console:
> mail = TMail::Mail.new
> mail.multipart?
=> false
> attachment = TMail::Mail.new
> attachment.body = CONTENT_FOR_ATTACHMENT (remember to encode the
content first)
> attachment.content_type = CONTENT''S_MIME_TYPE
> mail.parts << attachment
> mail.multipart?
=> true
> mail.to = MY_EMAIL
> ActionMailer::Base.deliver mail
and i received the email... with an attachment and a mime-boundary and
all that black-magic
i think i had to do some tricks so that it would still just be a single
call to my mailer... you could do something like:
def my_mail
# for templates and stuff
end
# override the ActionMailer one
def deliver_my_mail
mail = create_my_mail
# add attachment
self.deliver(mail)
end
but this would mean create and deliver were subtly different to the
ActionMailer default ones...
hope this helps...
Bodhi
[1] http://i.loveruby.net/en/man/tmail/index.html