class MIME::Mail

Construct RFC 2822 Internet messages.

Attributes

body[R]
headers[R]

Public Class Methods

new(content = nil) click to toggle source

Initialize a Mail object with body set to content.

# File lib/mime/mail.rb, line 18
def initialize content = nil
  @headers = Header.new
  self.body = content
  self.date = Time.now
end

Public Instance Methods

body=(content) click to toggle source
# File lib/mime/mail.rb, line 41
def body= content
  @body = content.is_a?(Media) ? content : Text.new(content.to_s)
end
to_s() click to toggle source

Format the Mail object as an Internet message.

# File lib/mime/mail.rb, line 27
def to_s
  self.sender       ||= sender_address
  self.message_id   ||= ID.generate_gid(domain)
  body.mime_version ||= "1.0 (Ruby MIME v#{VERSION})"

  #--
  # In an RFC 2822 message, the header and body sections must be separated
  # by two line breaks (i.e., 2*CRLF). One line break is deliberately
  # omitted here so the MIME body supplier can append headers to the
  # top-level message header section.
  #++
  "#{headers}\r\n#{body}"
end