class ActionMailer::Base
def attachments
mail.attachments[0] # => Mail::Part (first attachment)
# or by index
mail.attachments['filename.jpg'] # => Mail::Part object or nil
# By Filename
You can also search for specific attachments:
content: file_content }
encoding: 'SpecialEncoding',
mail.attachments['filename.jpg'] = {mime_type: 'application/gzip',
file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
data:
type along with the pre-encoded content as Mail doesn't know how to decode the
If you want to use encoding other than Base64 then you will need to pass encoding
content: File.read('/path/to/filename.jpg')}
mail.attachments['filename.jpg'] = {mime_type: 'application/gzip',
You can also specify overrides if you want by passing a hash instead of a string:
and encode the contents of the attachment in Base64.
It will also set the +Content-Type+, +Content-Disposition+, and +Content-Transfer-Encoding+,
If you do this, then Mail will take the file name and work out the mime type.
mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
Allows you to add attachments to an email, like so:
def attachments if @_mail_was_called LateAttachmentsProxy.new(@_message.attachments) else @_message.attachments end end