aboutsummaryrefslogtreecommitdiffstats
path: root/lib/net/smtp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net/smtp.rb')
-rw-r--r--lib/net/smtp.rb60
1 files changed, 50 insertions, 10 deletions
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 7a04aa2aa2..4b2986dea2 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -10,7 +10,7 @@ You can freely distribute/modify this library.
=end
-require 'net/session'
+require 'net/protocol'
module Net
@@ -47,6 +47,21 @@ Net::Protocol
* Net::ProtoUnknownError: unknown error
* Net::ProtoServerBusy: temporary error (errno.420/450)
+: ready( from_domain, to_addrs ) {|adapter| .... }
+ This method stands by the SMTP object for sending mail.
+ In the block of this iterator, you can call ONLY 'write' method
+ for 'adapter'.
+
+ # usage example
+
+ SMTP.start( 'localhost', 25 ) do |smtp|
+ smtp.ready( from, to ) do |adapter|
+ adapter.write str1
+ adapter.write str2
+ adapter.write str3
+ end
+ end
+
: finish
This method ends SMTP.
If protocol had not started, do nothind and return false.
@@ -59,14 +74,21 @@ Net::Protocol
protocol_param :command_type, '::Net::SMTPCommand'
- def sendmail( mailsrc, fromaddr, toaddrs )
+ def sendmail( mailsrc, fromaddr, toaddrs, &block )
@command.mailfrom fromaddr
@command.rcpt toaddrs
@command.data
- @command.sendmail mailsrc
+ @command.write_mail( mailsrc, &block )
+ end
+
+ def ready( fromaddr, toaddrs, &block )
+ sendmail nil, fromaddr, toaddrs, &block
end
+ attr :esmtp
+
+
private
@@ -74,7 +96,14 @@ Net::Protocol
unless helodom then
raise ArgumentError, "cannot get hostname"
end
- @command.helo helodom
+
+ @esmtp = false
+ begin
+ @command.ehlo helodom
+ @esmtp = true
+ rescue ProtocolError
+ @command.helo helodom
+ end
end
end
@@ -110,9 +139,15 @@ Net::Command
This method sends "RCPT TO" command.
to_addrs is array of mail address(???@???) of destination.
-: data( mailsrc )
- This method send 'mailsrc' as mail. SMTP reads strings from 'mailsrc'
- by calling 'each' iterator.
+: data
+ This method sends "DATA" command.
+
+: write_mail( mailsrc )
+: write_mail {|socket| ... }
+ send 'mailsrc' as mail.
+ SMTPCommand reads strings from 'mailsrc' by calling 'each' iterator.
+ When iterator, SMTPCommand only stand by socket and pass it.
+ (The socket will accepts only 'in_write' method in the block)
: quit
This method sends "QUIT" command and ends SMTP session.
@@ -132,6 +167,11 @@ Net::Command
end
+ def ehlo( fromdom )
+ getok sprintf( 'EHLO %s', fromdom )
+ end
+
+
def mailfrom( fromaddr )
getok sprintf( 'MAIL FROM:<%s>', fromaddr )
end
@@ -149,11 +189,11 @@ Net::Command
end
- def writemail( mailsrc )
- @socket.write_pendstr mailsrc
+ def write_mail( mailsrc, &block )
+ @socket.write_pendstr mailsrc, &block
check_reply SuccessCode
end
- alias sendmail writemail
+ alias sendmail write_mail
private