Ruby on Rails ActionMailer Adding Attachments


Example

ActionMailer also allows attaching files.

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

By default, attachments will be encoded with Base64. To change this, you can add a hash to the attachments method.

attachments['filename.jpg'] = {
  mime_type: 'application/gzip',
  encoding: 'SpecialEncoding',
  content: encoded_content
}

You can also add inline attachments

attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')