Class: BlitzSMTP::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/blitz_smtp/client.rb
Defined Under Namespace
Classes: AlreadyConnected, EHLOUnsupported, NotConnected, PipeliningUnsupported
Instance Method Summary
collapse
Constructor Details
#initialize(address, port) ⇒ Client
Returns a new instance of Client.
9
10
11
|
# File 'lib/blitz_smtp/client.rb', line 9
def initialize(address, port)
@server_address, @server_port = address, port
end
|
Instance Method Details
#connect ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/blitz_smtp/client.rb', line 13
def connect
raise AlreadyConnected if connected?
@socket = TCPSocket.open @server_address, @server_port
read_response check_features
rescue
disconnect if connected?
raise
end
|
#connected? ⇒ Boolean
31
32
33
|
# File 'lib/blitz_smtp/client.rb', line 31
def connected?
not @socket.nil?
end
|
#disconnect ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/blitz_smtp/client.rb', line 23
def disconnect
raise NotConnected unless connected?
send_command "QUIT"
read_response
@socket.close
@socket = nil
end
|
#send_message(from, to, message) ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/blitz_smtp/client.rb', line 35
def send_message(from, to, message)
send_command "MAIL", "FROM:#{format_address(from)}"
send_command "RCPT", "TO:#{format_address(to)}"
send_command "DATA"
3.times { read_response }
send_data message
read_response
end
|