method
attachments
v7.0.0 -
Show latest stable
-
0 notes -
Class: ActionMailer::Base
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-38)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-11)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (-22)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (8)
- 7.1.3.4 (0)
- What's this?
attachments()
public
Allows you to add attachments to an email, 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 type. It will also set the Content-Type, Content-Disposition, Content-Transfer-Encoding and encode the contents of the attachment in Base64.
You can also specify overrides if you want by passing a hash instead of a string:
mail.attachments['filename.jpg'] = {mime_type: 'application/gzip', content: File.read('/path/to/filename.jpg')}
If you want to use encoding other than Base64 then you will need to pass encoding type along with the pre-encoded content as Mail doesn’t know how to decode the data:
file_content = SpecialEncode(File.read('/path/to/filename.jpg')) mail.attachments['filename.jpg'] = {mime_type: 'application/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)