class Athena::MIME::Email

Overview

Provides a high-level API for creating an email.

email = AMIME::Email
  .new
  .from("[email protected]")
  .to("[email protected]")
  .cc("[email protected]")
  .bcc("[email protected]")
  .reply_to("[email protected]")
  .priority(:high)
  .subject("Important Notification")
  .text("Lorem ipsum...")
  .html("<h1>Lorem ipsum</h1> <p>...</p>")
  .attach_from_path("/path/to/file.pdf", "my-attachment.pdf")
  .embed_from_path("/path/to/logo.png")

# ...

Direct Known Subclasses

Defined in:

email.cr

Instance Method Summary

Instance methods inherited from class Athena::MIME::Message

body : AMIME::Part::Abstract | Nil body, body=(body : AMIME::Part::Abstract | Nil) body=, ensure_validity! : Nil ensure_validity!, generate_message_id : String generate_message_id, headers : AMIME::Header::Collection headers, headers=(headers : AMIME::Header::Collection) headers=, prepared_headers : AMIME::Header::Collection prepared_headers

Constructor methods inherited from class Athena::MIME::Message

new(headers : AMIME::Header::Collection | Nil = nil, body : AMIME::Part::Abstract | Nil = nil) new

Instance Method Detail

def add_bcc(*addresses : AMIME::Address | String) : self #

Appends the provided addresses to the list of current bcc addresses.


[View source]
def add_cc(*addresses : AMIME::Address | String) : self #

Appends the provided addresses to the list of current cc addresses.


[View source]
def add_from(*addresses : AMIME::Address | String) : self #

Appends the provided addresses to the list of current from addresses.


[View source]
def add_part(part : AMIME::Part::Data) : self #

Adds the provided part as an email attachment. Consider using #attach or #embed or one of their variants to provide a simpler API.


[View source]
def add_reply_to(*addresses : AMIME::Address | String) : self #

Appends the provided addresses to the list of current reply-to addresses.


[View source]
def add_to(*addresses : AMIME::Address | String) : self #

Appends the provided addresses to the list of current to addresses.


[View source]
def attach(body : String | IO, name : String | Nil = nil, content_type : String | Nil = nil) : self #

Adds an attachment with the provided body, optionally with the provided name and content_type.


[View source]
def attach_from_path(path : String | Path, name : String | Nil = nil, content_type : String | Nil = nil) : self #

Attaches the file at the provided path as an attachment, optionally with the provided name and content_type.


[View source]
def attachments : Array(AMIME::Part::Data) #

Returns an array of AMIME::Part::Data representing the email's attachments.


[View source]
def bcc : Array(AMIME::Address) #

Returns the bcc addresses of this email, or an empty array if none were set.


[View source]
def bcc(*addresses : AMIME::Address | String) : self #

Sets the cc addresses of this email to the provided addresses, overriding any previously added ones.


[View source]

Returns the MIME representation of this email.


[View source]
def cc : Array(AMIME::Address) #

Returns the cc addresses of this email, or an empty array if none were set.


[View source]
def cc(*addresses : AMIME::Address | String) : self #

Sets the cc addresses of this email to the provided addresses, overriding any previously added ones.


[View source]
def date(date : Time) : self #

Sets the date of this email to the provided date.


[View source]
def date : Time | Nil #

Returns the date of this email, or nil if none is set.


[View source]
def embed(body : String | IO, name : String | Nil = nil, content_type : String | Nil = nil) : self #

Adds an embedded attachment with the provided body, optionally with the provided name and content_type.


[View source]
def embed_from_path(path : String | Path, name : String | Nil = nil, content_type : String | Nil = nil) : self #

Embeds the file at the provided path as an attachment, optionally with the provided name and content_type.


[View source]
def ensure_validity! : Nil #

Asserts that this message is in a valid state to be sent, raising an AMIME::Exception::Logic error if not.


[View source]
def from : Array(AMIME::Address) #

Returns the from addresses of this email, or an empty array if none were set.


[View source]
def from(*addresses : AMIME::Address | String) : self #

Sets the from addresses of this email to the provided addresses, overriding any previously added ones.


[View source]
def html(body : String | IO | Nil, charset : String = "UTF-8") : self #

Sets the HTML content of this email to the provided body, optionally with the provided charset.


[View source]
def html_body : IO | String | Nil #

Returns the HTML content of this email.


[View source]
def html_charset : String | Nil #

Returns the charset of the #html_body for this email.


[View source]
def priority(priority : AMIME::Email::Priority) : self #

Sets the priority of this email to the provided priority.


[View source]
def priority : AMIME::Email::Priority #

Returns the priority of this email.


[View source]
def reply_to : Array(AMIME::Address) #

Returns the reply-to addresses of this email, or an empty array if none were set.


[View source]
def reply_to(*addresses : AMIME::Address | String) : self #

Sets the reply-to addresses of this email to the provided addresses, overriding any previously added ones.


[View source]
def return_path(address : AMIME::Address | String) : self #

Sets the return path of this email to the provided address.


[View source]
def return_path : AMIME::Address | Nil #

Returns the return path of this email, or nil if none is set.


[View source]
def sender(address : AMIME::Address | String) : self #

Sets the sender of this email to the provided address.


[View source]
def sender : AMIME::Address | Nil #

Returns the sender of this email, or nil if none is set.


[View source]
def subject(subject : String) : self #

Sets the subject of this email to the provided subject.


[View source]
def subject : String | Nil #

Returns the subject of this email, or nil if none is set.


[View source]
def text(body : String | IO | Nil, charset : String = "UTF-8") : self #

Sets the textual content of this email to the provided body, optionally with the provided charset.


[View source]
def text_body : IO | String | Nil #

Returns the textual content of this email.


[View source]
def text_charset : String | Nil #

Returns the charset of the #text_body for this email.


[View source]
def to : Array(AMIME::Address) #

Returns the to addresses of this email, or an empty array if none were set.


[View source]
def to(*addresses : AMIME::Address | String) : self #

Sets the to addresses of this email to the provided addresses, overriding any previously added ones.


[View source]