@@ -146,8 +146,8 @@ class SMTPUnsupportedCommand < ProtocolError
146
146
# The SMTP server will judge whether it should send or reject
147
147
# the SMTP session by inspecting the HELO domain.
148
148
#
149
- # Net::SMTP.start('your.smtp.server', 25,
150
- # 'mail.from.domain') { |smtp| ... }
149
+ # Net::SMTP.start('your.smtp.server', 25
150
+ # helo: 'mail.from.domain') { |smtp| ... }
151
151
#
152
152
# === SMTP Authentication
153
153
#
@@ -157,15 +157,15 @@ class SMTPUnsupportedCommand < ProtocolError
157
157
# SMTP.start/SMTP#start.
158
158
#
159
159
# # PLAIN
160
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
161
- # 'Your Account', 'Your Password', :plain)
160
+ # Net::SMTP.start('your.smtp.server', 25
161
+ # user: 'Your Account', secret: 'Your Password', authtype: :plain)
162
162
# # LOGIN
163
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
164
- # 'Your Account', 'Your Password', :login)
163
+ # Net::SMTP.start('your.smtp.server', 25
164
+ # user: 'Your Account', secret: 'Your Password', authtype: :login)
165
165
#
166
166
# # CRAM MD5
167
- # Net::SMTP.start('your.smtp.server', 25, 'mail.from.domain',
168
- # 'Your Account', 'Your Password', :cram_md5)
167
+ # Net::SMTP.start('your.smtp.server', 25
168
+ # user: 'Your Account', secret: 'Your Password', authtype: :cram_md5)
169
169
#
170
170
class SMTP < Protocol
171
171
@@ -400,12 +400,16 @@ def debug_output=(arg)
400
400
# SMTP session control
401
401
#
402
402
403
+ #
404
+ # :call-seq:
405
+ # start(address, port = nil, helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
406
+ # start(address, port = nil, helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
403
407
#
404
408
# Creates a new Net::SMTP object and connects to the server.
405
409
#
406
410
# This method is equivalent to:
407
411
#
408
- # Net::SMTP.new(address, port).start(helo_domain, account, password, authtype)
412
+ # Net::SMTP.new(address, port).start(helo: helo_domain, user: account, secret: password, authtype: authtype)
409
413
#
410
414
# === Example
411
415
#
@@ -449,17 +453,26 @@ def debug_output=(arg)
449
453
# * Net::ReadTimeout
450
454
# * IOError
451
455
#
452
- def SMTP . start ( address , port = nil , helo = 'localhost' ,
453
- user = nil , secret = nil , authtype = nil ,
454
- &block ) # :yield: smtp
455
- new ( address , port ) . start ( helo , user , secret , authtype , &block )
456
+ def SMTP . start ( address , port = nil , *args , helo : nil ,
457
+ user : nil , secret : nil , password : nil , authtype : nil ,
458
+ &block )
459
+ raise ArgumentError , "wrong number of arguments (given #{ args . size + 2 } , expected 1..6)" if args . size > 4
460
+ helo ||= args [ 0 ] || 'localhost'
461
+ user ||= args [ 1 ]
462
+ secret ||= password || args [ 2 ]
463
+ authtype ||= args [ 3 ]
464
+ new ( address , port ) . start ( helo : helo , user : user , secret : secret , authtype : authtype , &block )
456
465
end
457
466
458
467
# +true+ if the SMTP session has been started.
459
468
def started?
460
469
@started
461
470
end
462
471
472
+ #
473
+ # :call-seq:
474
+ # start(helo: 'localhost', user: nil, secret: nil, authtype: nil) { |smtp| ... }
475
+ # start(helo = 'localhost', user = nil, secret = nil, authtype = nil) { |smtp| ... }
463
476
#
464
477
# Opens a TCP connection and starts the SMTP session.
465
478
#
@@ -487,7 +500,7 @@ def started?
487
500
#
488
501
# require 'net/smtp'
489
502
# smtp = Net::SMTP.new('smtp.mail.server', 25)
490
- # smtp.start(helo_domain, account, password, authtype) do |smtp|
503
+ # smtp.start(helo: helo_domain, user: account, secret: password, authtype: authtype) do |smtp|
491
504
# smtp.send_message msgstr, 'from@example.com', ['dest@example.com']
492
505
# end
493
506
#
@@ -511,8 +524,13 @@ def started?
511
524
# * Net::ReadTimeout
512
525
# * IOError
513
526
#
514
- def start ( helo = 'localhost' ,
515
- user = nil , secret = nil , authtype = nil ) # :yield: smtp
527
+ def start ( *args , helo : nil ,
528
+ user : nil , secret : nil , password : nil , authtype : nil )
529
+ raise ArgumentError , "wrong number of arguments (given #{ args . size } , expected 0..4)" if args . size > 4
530
+ helo ||= args [ 0 ] || 'localhost'
531
+ user ||= args [ 1 ]
532
+ secret ||= password || args [ 2 ]
533
+ authtype ||= args [ 3 ]
516
534
if block_given?
517
535
begin
518
536
do_start helo , user , secret , authtype
0 commit comments