class EMail::Message
- EMail::Message
- Reference
- Object
Overview
Email message object.
Minimal email with plain text message.
email = EMail::Message.new
# Email headers
email.from "[email protected]"
email.to "[email protected]"
email.subject "Subject of the mail"
# Email plain text email body
email.message <<-EOM
  Message body of the mail.
  --
  Your Signature
  EOMYou can set following preset headers and your own #custom_headers:
- [*][!] #from
- [*][?] #to
- [*][?] #cc
- [*][?] #bcc
- [*] #reply_to
- #return_path
- #sender
- #envelope_from
- [!] #subject
[!] required.
[*] usable multiple times.
[?] required at least one recipient.
Set custom header
email.custom_header "X-Mailer", "Your APP Name"Set mailbox name with email address
email.from "[email protected]", "your name"HTML email with altanative plain text message.
email = EMail::Message.new
# Email headers
email.from "[email protected]"
email.to "[email protected]"
email.subject "Subject of the mail"
# Email plain text email body
email.message <<-EOM
  Message body of the mail.
  --
  Your Signature
  EOM
# Email HTML email body
email.message_html <<-EOM
  <html>
  <body>
  <h1>Subject of the mail<h1>
  <p>Message body of the mail.</p>
  <footer>
  Your Signature
  </footer>
  </body>
  </html>
  EOMAttache files
email = EMail::Message.new
# Email headers
email.from "[email protected]"
email.to "[email protected]"
email.subject "Subject of the mail"
# Email plain text email body
email.message <<-EOM
  Message body of the mail.
  --
  Your Signature
  EOM
# Attach file to email
email.attach "./photo.jpeg"Set alternative file name for recipient
email.attach "./photo.jpeg", file_name: "last_year.jpeg"Set specific MIME type
email.attach "./data", mime_type: "text/csv"Read attachment file data from IO
email.attach io, file_name: "photo.jpeg"In this case, file_name argument is required.
Add message resouces
email = EMail::Message.new
# Email headers
email.from "[email protected]"
email.to "[email protected]"
email.subject "Subject of the mail"
# Email plain text email body
email.message <<-EOM
  Message body of the mail.
  --
  Your Signature
  EOM
# Email HTML email body
email.message_html <<-EOM
  <html>
  <body>
  <img src="cid:[email protected]">
  <h1>Subject of the mail<h1>
  <p>Message body of the mail.</p>
  <footer>
  Your Signature
  </footer>
  </body>
  </html>
  EOM
# Add message resource
email.message_resource "./logo.png", cid: "[email protected]"#message_resource is lmost same as #attach expect it requires cid argument.
Defined in:
email/message.crInstance Method Summary
- 
        #attach(file_path : String, file_name : String | Nil = nil, mime_type : String | Nil = nil)
        
          Attache the file from given file path. 
- 
        #attach(io : IO, file_name : String, mime_type : String | Nil = nil)
        
          Attache the file read from given IO. 
- 
        #bcc(mail_address : String, sender_name : String | Nil = nil)
        
          Add email address to Bcc header. 
- 
        #bcc(mail_address : EMail::Address)
        
          Add email address to Bcc header. 
- 
        #cc(mail_address : String, sender_name : String | Nil = nil)
        
          Add email address to Cc header. 
- 
        #cc(mail_address : EMail::Address)
        
          Add email address to Cc header. 
- 
        #custom_header(name : String, value : String)
        
          Set cuntome header you want to set to the message. 
- 
        #envelope_from(mail_address : String)
        
          Set envelope from address. 
- 
        #from(mail_address : String, sender_name : String | Nil = nil)
        
          Add email address to From header. 
- 
        #from(mail_address : EMail::Address)
        
          Add email address to From header. 
- 
        #message(message_body : String)
        
          Set plain text message body. 
- 
        #message_html(message_body : String)
        
          Set html text message body. 
- 
        #message_id(header_body : String)
        
          Set Message-Id header. 
- 
        #message_resource(file_path : String, cid : String, file_name : String | Nil = nil, mime_type : String | Nil = nil)
        
          Add message resource file, such as images or stylesheets for the html message, from given file path. 
- 
        #message_resource(io : IO, cid : String, file_name : String, mime_type : String | Nil = nil)
        
          Add message resource file, such as images or stylesheets for the html message, read from given IO. 
- 
        #reply_to(mail_address : String, sender_name : String | Nil = nil)
        
          Add email address to Reply-To header. 
- 
        #reply_to(mail_address : EMail::Address)
        
          Add email address to Reply-To header. 
- 
        #return_path(mail_address : String, sender_name : String | Nil = nil)
        
          Set email address to Return-Path header. 
- 
        #return_path(mail_address : EMail::Address)
        
          Set email address to Return-Path header. 
- 
        #sender(mail_address : String, sender_name : String | Nil = nil)
        
          Set email address to Sender header. 
- 
        #sender(mail_address : EMail::Address)
        
          Set email address to Sender header. 
- 
        #subject(header_body : String)
        
          Set Subject header. 
- 
        #to(mail_address : String, sender_name : String | Nil = nil)
        
          Add email address to To header. 
- 
        #to(mail_address : EMail::Address)
        
          Add email address to To header. 
- 
        #to_s(io : IO)
        
          Appends a short String representation of this object which includes its class name and its object address. 
Instance Method Detail
Attache the file from given file path.
You can set another file_name for recipients and sprcific mime_type.
By default, MIME type will be inferred from extname of the file name.
Attache the file read from given IO.
In this case, file_name argument is required.
Set cuntome header you want to set to the message.
Add email address to From header.
Add message resource file, such as images or stylesheets for the html message, from given file path.
Almost same as #attach expect this require cid argument.
Add message resource file, such as images or stylesheets for the html message, read from given IO.
Almost same as #attach expect this require cid argument.
Add email address to Reply-To header.
Set email address to Return-Path header.
Set email address to Sender header.
Appends a short String representation of this object which includes its class name and its object address.
class Person
  def initialize(@name : String, @age : Int32)
  end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>