Class: Net::SMTP::Response (Ruby 2.3.7)
Description: Class : Net::SMTP::Response - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- net/smtp.rb

### Parent

Object

### Methods

- ::new
- ::parse
- #capabilities
- #continue?
- #cram_md5_challenge
- #exception_class
- #message
- #status_type_char
- #success?

### Class/Module Index

Quicksearch

- Net
- Net::SMTP
- Net::SMTP::Response
- Net::SMTPAuthenticationError
- Net::SMTPError
- Net::SMTPFatalError
- Net::SMTPServerBusy
- Net::SMTPSyntaxError
- Net::SMTPUnknownError
- Net::SMTPUnsupportedCommand

No matching classes.

# Net::SMTP::Response

This class represents a response received by the SMTP server. Instances of this class are created by the SMTP class; they should not be directly created by the user. For more information on SMTP responses, view Section 4.2 of RFC 5321

### Attributes

status[R]

The three digit reply code of the SMTP response

string[R]

The human readable reply text of the SMTP response

### Public Class Methods

new(status, string) click to toggle source

Creates a new instance of the Response class and sets the status and string attributes

                   # File net/smtp.rb, line 1008
    def initialize(status, string)
      @status = status
      @string = string
    end

parse(str) click to toggle source

Parses the received response and separates the reply code and the human readable reply text

                   # File net/smtp.rb, line 1002
    def self.parse(str)
      new(str[0,3], str)
    end

### Public Instance Methods

capabilities() click to toggle source

Returns a hash of the human readable reply text in the response if it is multiple lines. It does not return the first line. The key of the hash is the first word the value of the hash is an array with each word thereafter being a value in the array

                   # File net/smtp.rb, line 1051
    def capabilities
      return {} unless @string[3, 1] == '-'
      h = {}
      @string.lines.drop(1).each do |line|
        k, *v = line[4..-1].chomp.split
        h[k] = v
      end
      h
    end

continue?() click to toggle source

Determines whether the response received was a Positive Intermediate reply (3xx reply code)

                   # File net/smtp.rb, line 1032
    def continue?
      status_type_char() == '3'
    end

cram_md5_challenge() click to toggle source

Creates a CRAM-MD5 challenge. You can view more information on CRAM-MD5 on Wikipedia: en.wikipedia.org/wiki/CRAM-MD5

                   # File net/smtp.rb, line 1043
    def cram_md5_challenge
      @string.split(/ /)[1].unpack('m')[0]
    end

exception_class() click to toggle source

Determines whether there was an error and raises the appropriate error based on the reply code of the response

                   # File net/smtp.rb, line 1063
    def exception_class
      case @status
      when /\A4/  then SMTPServerBusy
      when /\A50/ then SMTPSyntaxError
      when /\A53/ then SMTPAuthenticationError
      when /\A5/  then SMTPFatalError
      else             SMTPUnknownError
      end
    end

message() click to toggle source

The first line of the human readable reply text

                   # File net/smtp.rb, line 1037
    def message
      @string.lines.first
    end

status_type_char() click to toggle source

Takes the first digit of the reply code to determine the status type

                   # File net/smtp.rb, line 1020
    def status_type_char
      @status[0, 1]
    end

success?() click to toggle source

Determines whether the response received was a Positive Completion reply (2xx reply code)

                   # File net/smtp.rb, line 1026
    def success?
      status_type_char() == '2'
    end