devise

https://github.com/plataformatec/devise

Ruby

Flexible authentication solution for Rails with Warden.

Mail::Message#attachments

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

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

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

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

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

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

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

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

You can also search for specific attachments:

 # By Filename
 mail.attachments['filename.jpg']   #=> Mail::Part object or nil

 # or by index
 mail.attachments[0]                #=> Mail::Part (first attachment)

Source | Google | Stack overflow

Edit

git clone [email protected]:plataformatec/devise.git

cd devise

open

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Mail--Message-attachments-for-pr


# Commit to git

git add git commit -m "better docs for Mail::Message#attachments"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Mail--Message-attachments-for-pr

hub pull-request


# Celebrate!