class Ronin::Support::Network::SMTP::Email
Represents an Email
to be sent over {SMTP}.
Constants
- CRLF
-
The CR-LF
String
Attributes
Date of the email
@return [String, Time]
Sender of the email
@return [String]
Additional headers
@return [Hash{String => String}]
Unique message-id string
@return [String]
Subject of the email
@return [String]
Recipient of the email
@return [Array<#to_s>, String]
Public Class Methods
Source
# 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
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
Public Instance Methods
Source
# 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
Formats the email into a SMTP
message.
@return [String]
Properly formatted SMTP message.
@see rubydoc.info/stdlib/net/Net/SMTP
@api public