class Mail::Message

Direct Known Subclasses

Defined in:

mail/message.cr

Constant Summary

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

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(raw_source = "", body : Body = Body.new) #

[View source]

Class Method Detail

def self.charset : String #

[View source]
def self.charset=(charset : String) #

[View source]

Instance Method Detail

def add_part(part) #

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


[View source]
def all_parts #

[View source]
def 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...


[View source]
def 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'


[View source]
def body_lazy(value) #

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


[View source]
def boundary #

Returns the current boundary for this message part


[View source]
def charset #

Returns the character set defined in the content type field


[View source]
def charset=(value : String) #

Sets the charset to the supplied value.


[View source]
def content_transfer_encoding(val = nil) #

[View source]
def content_transfer_encoding=(val) #

[View source]
def content_type(val = nil) #

[View source]
def content_type=(val) #

[View source]
def content_type_parameters #

Returns the content type parameters


[View source]
def 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.


[View source]
def envelope_date #

[View source]
def envelope_from #

[View source]
def find_first_mime_type(ct) #

[View source]
def from(val = nil) #

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

Example:

mail.from = 'Mikel [email protected]' mail.from #=> ['[email protected]'] mail.from = 'Mikel [email protected], [email protected]' mail.from #=> ['[email protected]', '[email protected]']

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

Example:

mail.from 'Mikel [email protected]' mail.from #=> ['[email protected]']

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

Example:

mail.from 'Mikel [email protected]' mail.from << '[email protected]' mail.from #=> ['[email protected]', '[email protected]']


[View source]
def from=(val) #

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

Example:

mail.from = 'Mikel [email protected]' mail.from #=> ['[email protected]'] mail.from = 'Mikel [email protected], [email protected]' mail.from #=> ['[email protected]', '[email protected]']


[View source]
def has_content_transfer_encoding? #

[View source]
def has_content_type? #

[View source]
def 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...


[View source]
def header=(value) #

Sets the header of the message object.

Example:

mail.header = 'To: [email protected]\r\nFrom: [email protected]' mail.header #=> <#Mail::Header


[View source]
def html_part #

Accessor for html_part


[View source]
def html_part(&block) #

[View source]
def main_type #

Returns the main content type


[View source]
def mime_type #

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


[View source]
def multipart? #

Returns true if the message is multipart


[View source]
def parts #

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


[View source]
def raw_envelope : String? #

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


[View source]
def raw_source : String #

[View source]
def raw_source=(raw_source : String) #

[View source]
def set_envelope(raw_envelope : String) #

[View source]
def text_part #

Accessor for text_part


[View source]
def text_part(&block) #

[View source]
def 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.


[View source]
def to(val = nil) #

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

Example:

mail.to = 'Mikel [email protected]' mail.to #=> ['[email protected]'] mail.to = 'Mikel [email protected], [email protected]' mail.to #=> ['[email protected]', '[email protected]']

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

Example:

mail.to 'Mikel [email protected]' mail.to #=> ['[email protected]']

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

Example:

mail.to 'Mikel [email protected]' mail.to << '[email protected]' mail.to #=> ['[email protected]', '[email protected]']


[View source]
def to=(val) #

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

Example:

mail.to = 'Mikel [email protected]' mail.to #=> ['[email protected]'] mail.to = 'Mikel [email protected], [email protected]' mail.to #=> ['[email protected]', '[email protected]']


[View source]