mail

https://github.com/mikel/mail

Ruby

A Really Ruby Mail Library

Mail::Message#add_file

Adds a file to the message.  You have two options with this method, you can
just pass in the absolute path to the file you want and Mail will read the file,
get the filename from the path you pass in and guess the MIME media type, or you
can pass in the filename as a string, and pass in the file content as a blob.

Example:

 m = Mail.new
 m.add_file('/path/to/filename.png')

 m = Mail.new
 m.add_file(:filename => 'filename.png', :content => File.read('/path/to/file.jpg'))

Note also that if you add a file to an existing message, Mail will convert that message
to a MIME multipart email, moving whatever plain text body you had into its own text
plain part.

Example:

 m = Mail.new do
   body 'this is some text'
 end
 m.multipart? #=> false
 m.add_file('/path/to/filename.png')
 m.multipart? #=> true
 m.parts.first.content_type.content_type #=> 'text/plain'
 m.parts.last.content_type.content_type #=> 'image/png'

See also #attachments

Source | Google | Stack overflow

Edit

git clone [email protected]:mikel/mail.git

cd mail

open lib/mail/message.rb

Contribute

# Make a new branch

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


# Commit to git

git add lib/mail/message.rbgit commit -m "better docs for Mail::Message#add_file"


# 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-add_file-for-pr

hub pull-request


# Celebrate!