lib/ronin/network/extensions/smtp/net.rb in ronin-support-0.1.0 vs lib/ronin/network/extensions/smtp/net.rb in ronin-support-0.2.0.rc1

- old
+ new

@@ -15,20 +15,34 @@ # # You should have received a copy of the GNU Lesser General Public License # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>. # +require 'ronin/network/smtp/smtp' require 'ronin/network/smtp/email' require 'net/smtp' module Net # - # @see Ronin::Network::SMTP.message + # Creates a new email message. # + # @param [Hash] options + # Additional options for the email. + # + # @yield [email] + # The given block will be passed the new email. + # + # @yieldparam [Ronin::Network::SMTP::Email] email + # The new email. + # + # @see Ronin::Network::SMTP::Email.new + # + # @api public + # def Net.smtp_message(options={},&block) - Ronin::Network::SMTP.message(options,&block) + Ronin::Network::SMTP::Email.new(options,&block) end # # Creates a connection to the SMTP server. # @@ -61,10 +75,15 @@ # The SMTP session. # # @return [Net::SMTP] # The SMTP session. # + # @example + # Net.smtp_connect('www.example.com', :user => 'joe') + # + # @api public + # def Net.smtp_connect(host,options={}) host = host.to_s port = (options[:port] || Ronin::Network::SMTP.default_port) helo = options[:helo] @@ -93,16 +112,68 @@ # After the block has returned, the session will be closed. # # @yieldparam [Net::SMTP] session # The SMTP session. # + # @example + # Net.smtp_session('www.example.com', :user => 'joe') do |smtp| + # # ... + # end + # # @see Net.smtp_connect # + # @api public + # def Net.smtp_session(host,options={}) session = Net.smtp_connect(host,options) yield session if block_given? session.finish return nil + end + + # + # @since 0.2.0 + # + # @param [String] host + # The host to connect to. + # + # @param [Hash] options + # Additional SMTP and Email options. + # + # @yield [email] + # The given block will be passed the new email to be sent. + # + # @yieldparam [Ronin::Network::SMTP::Email] email + # The new email to be sent. + # + # @see Net.smtp_session + # + # @example + # Net.smtp_send_message 'www.example.com', :to => 'joe@example.com', + # :from => 'eve@example.com', + # :subject => 'Hello', + # :message_id => 'XXXX', + # :body => 'Hello' + # + # @example Using the block. + # Net.smtp_send_message('www.example.com') do |email| + # email.to = 'joe@example.com' + # email.from 'eve@example.com' + # email.subject = 'Hello' + # email.message_id = 'XXXXXXXXXX' + # email.body << 'Hello!' + # end + # + # @since 0.2.0 + # + # @api public + # + def Net.smtp_send_message(host,options={},&block) + email = Net.smtp_message(options,&block) + + Net.smtp_session(host,options) do |smtp| + smtp.send_message(email.to_s, email.from, email.to) + end end end