class Ronin::Support::Network::SMTP::Email
Represents an Email
to be sent over {SMTP}.
Constants
- CRLF
The CR-LF
String
Attributes
body[RW]
Body of the email
@return [String, Array
<String>]
date[RW]
Date of the email
@return [String, Time]
from[RW]
Sender of the email
@return [String]
headers[R]
Additional headers
@return [Hash{String => String}]
message_id[RW]
Unique message-id string
@return [String]
subject[RW]
Subject of the email
@return [String]
to[RW]
Recipient of the email
@return [Array<#to_s>, String]
Public Class Methods
new(from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) { |self| ... }
click to toggle source
Creates a new Email
object.
@param [String] from
The address the email is from.
@param [Array<#to_s>, String] to
The address that the email should be sent to.
@param [String] subject
The subject of the email.
@param [String] message_id
Message-ID of the email.
@param [String, Time] date
The date the email was sent on.
@param [Hash<String => String}] headers
Additional headers.
@param [String, Array
<String>] body
The body of the email.
@yield [email]
If a block is given, it will be passed the newly created email object.
@yieldparam [Email] email
The newly created email object.
@api public
# File lib/ronin/support/network/smtp/email.rb, line 99 def initialize(from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) @from = from @to = to @subject = subject @date = date @message_id = message_id @headers = {} @headers.merge!(headers) if headers @body = [] if body case body when Array @body += body else @body << body end end yield self if block_given? end
Public Instance Methods
to_s()
click to toggle source
Formats the email into a SMTP
message.
@return [String]
Properly formatted SMTP message.
@see rubydoc.info/stdlib/net/Net/SMTP
@api public
# File lib/ronin/support/network/smtp/email.rb, line 139 def to_s message = [] if @from message << "From: #{@from}" end if @to message << case @to when Array "To: #{@to.join(', ')}" else "To: #{@to}" end end if @subject message << "Subject: #{@subject}" end if @date message << "Date: #{@date}" end if @message_id message << "Message-Id: <#{@message_id}>" end @headers.each do |name,value| message << "#{name}: #{value}" end message << '' message += @body return message.join(CRLF) end