class

Mail::Message

Inherits Reference < Object

Constants

HEADER_SEPARATOR = /#{Constants::LAX_CRLF}#{Constants::LAX_CRLF}/

Constructors

new(raw_source = "", body : Body = Body.new)
Source

Class methods

charset
Source
charset=(charset : String)
Source

Instance methods

add_part(part)

Adds a part to the parts list or creates the part list

Source
all_parts
Source
body(value = nil)

Returns the body of the message object. Or, if passed a parameter sets the value.

Example:

mail = Mail::Message.new('To: mikel\r\n\r\nThis is the body') mail.body #=> #<Mail::Body:0x13919c @raw_source="This is the bo...

mail.body 'This is another body' mail.body #=> #<Mail::Body:0x13919c @raw_source="This is anothe...

Source
body=(value)

Sets the body object of the message object.

Example:

mail.body = 'This is the body' mail.body #=> #<Mail::Body:0x13919c @raw_source="This is the bo...

You can also reset the body of an Message object by setting body to nil

Example:

mail.body = 'this is the body' mail.body.encoded #=> 'this is the body' mail.body = nil mail.body.encoded #=> ''

If you try and set the body of an email that is a multipart email, then instead of deleting all the parts of your email, mail will add a text/plain part to your email:

mail.add_file 'somefilename.png' mail.parts.length #=> 1 mail.body = "This is a body" mail.parts.length #=> 2 mail.parts.last.content_type.content_type #=> 'This is a body'

Source
body_lazy(value)

see comments to body=. We take data and process it lazily

Source
boundary

Returns the current boundary for this message part

Source
charset

Returns the character set defined in the content type field

Source
charset=(value : String)

Sets the charset to the supplied value.

Source
content_transfer_encoding(val = nil)
Source
content_transfer_encoding=(val)
Source
content_type(val = nil)
Source
content_type=(val)
Source
content_type_parameters

Returns the content type parameters

Source
default(str, val = nil)

Returns the default value of the field requested as a symbol.

Each header field has a :default method which returns the most common use case for that field, for example, the date field types will return a DateTime object when sent :default, the subject, or unstructured fields will return a decoded string of their value, the address field types will return a single addr_spec or an array of addr_specs if there is more than one.

Source
envelope_date
Source
envelope_from
Source
find_first_mime_type(ct)
Source
from(val = nil)

Returns the From value of the mail object as an array of strings of address specs.

Example:

mail.from = 'Mikel mikel@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net'] mail.from = 'Mikel mikel@test.lindsaar.net, ada@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Also allows you to set the value by passing a value as a parameter

Example:

mail.from 'Mikel mikel@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net']

Additionally, you can append new addresses to the returned Array like object.

Example:

mail.from 'Mikel mikel@test.lindsaar.net' mail.from << 'ada@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Source
from=(val)

Sets the From value of the mail object, pass in a string of the field

Example:

mail.from = 'Mikel mikel@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net'] mail.from = 'Mikel mikel@test.lindsaar.net, ada@test.lindsaar.net' mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Source
has_content_transfer_encoding?
Source
has_content_type?
Source
header(value = nil)

Returns the header object of the message object. Or, if passed a parameter sets the value.

Example:

mail = Mail::Message.new('To: mikel\r\nFrom: you') mail.header #=> #<Mail::Header:0x13ce14 @raw_source="To: mikel\r\nFr...

mail.header #=> nil mail.header 'To: mikel\r\nFrom: you' mail.header #=> #<Mail::Header:0x13ce14 @raw_source="To: mikel\r\nFr...

Source
header=(value)

Sets the header of the message object.

Example:

mail.header = 'To: mikel@test.lindsaar.net\r\nFrom: Bob@bob.com' mail.header #=> <#Mail::Header

Source
html_part

Accessor for html_part

Source
html_part
Source
main_type

Returns the main content type

Source
mime_type

Returns the MIME media type of part we are on, this is taken from the content-type header

Source
multipart?

Returns true if the message is multipart

Source
parts

Returns a parts list object of all the parts in the message

Source
raw_envelope

Type field that you can see at the top of any email that has come from a mailbox

Source
raw_source
Source
raw_source=(raw_source : String)
Source
set_envelope(raw_envelope : String)
Source
text_part

Accessor for text_part

Source
text_part
Source
text_part=(msg)

Helper to add a text part to a multipart/alternative email. If this and html_part are both defined in a message, then it will be a multipart/alternative message and set itself that way.

Source
to(val = nil)

Returns the To value of the mail object as an array of strings of address specs.

Example:

mail.to = 'Mikel mikel@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net'] mail.to = 'Mikel mikel@test.lindsaar.net, ada@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Also allows you to set the value by passing a value as a parameter

Example:

mail.to 'Mikel mikel@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net']

Additionally, you can append new addresses to the returned Array like object.

Example:

mail.to 'Mikel mikel@test.lindsaar.net' mail.to << 'ada@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Source
to=(val)

Sets the To value of the mail object, pass in a string of the field

Example:

mail.to = 'Mikel mikel@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net'] mail.to = 'Mikel mikel@test.lindsaar.net, ada@test.lindsaar.net' mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']

Source