Skip to content

class Athena::MIME::Email
inherits Athena::MIME::Message #

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

Athena::MIME::DraftEmail

Methods#

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

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

#add_cc(*addresses : AMIME::Address | String) : self#

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

#add_from(*addresses : AMIME::Address | String) : self#

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

#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.

#add_reply_to(*addresses : AMIME::Address | String) : self#

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

#add_to(*addresses : AMIME::Address | String) : self#

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

#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.

#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.

#attachments : Array(AMIME::Part::Data)#

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

#bcc : Array(AMIME::Address)#

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

#bcc(*addresses : AMIME::Address | String) : self#

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

#body : AMIME::Part::Abstract#

Returns the MIME representation of this email.

#cc : Array(AMIME::Address)#

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

#cc(*addresses : AMIME::Address | String) : self#

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

#date(date : Time) : self#

Sets the date of this email to the provided date.

#date : Time | ::Nil#

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

#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.

#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.

#ensure_validity! : Nil#

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

#from : Array(AMIME::Address)#

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

#from(*addresses : AMIME::Address | String) : self#

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

#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.

#html_body : IO | String | Nil#

Returns the HTML content of this email.

#html_charset : String | ::Nil#

Returns the charset of the #html_body for this email.

#priority(priority : AMIME::Email::Priority) : self#

Sets the priority of this email to the provided priority.

#priority : AMIME::Email::Priority#

Returns the priority of this email.

#reply_to : Array(AMIME::Address)#

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

#reply_to(*addresses : AMIME::Address | String) : self#

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

#return_path(address : AMIME::Address | String) : self#

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

#return_path : AMIME::Address | ::Nil#

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

#sender(address : AMIME::Address | String) : self#

Sets the sender of this email to the provided address.

#sender : AMIME::Address | ::Nil#

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

#subject(subject : String) : self#

Sets the subject of this email to the provided subject.

#subject : String | ::Nil#

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

#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.

#text_body : IO | String | Nil#

Returns the textual content of this email.

#text_charset : String | ::Nil#

Returns the charset of the #text_body for this email.

#to : Array(AMIME::Address)#

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

#to(*addresses : AMIME::Address | String) : self#

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