class Mail::Message

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/x-gzip',
file_content = SpecialEncode(File.read('/path/to/filename.jpg'))

Mail to know how to decode this data:
but then it is up to you to pass in the content pre-encoded, and don't expect
If you want to use a different encoding than Base64, you can pass an encoding in,

:content => File.read('/path/to/filename.jpg')}
mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',

You can also specify overrides if you want by passing a hash instead of a string:

base64 encode the contents of the attachment all for you.
set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
If you do this, then Mail will take the file name and work out the MIME media type

mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')

It also allows you to add attachments to the mail object directly, like so:

of its descendants.
the receiver object (either the entire email or a part within) and all
Returns an AttachmentsList object, which holds all of the attachments in
def attachments
  parts.attachments
end