@@ -458,6 +458,7 @@ def debug_output=(arg)
458
458
459
459
#
460
460
# :call-seq:
461
+ # start(address, port = nil, helo: 'localhost', auth: nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
461
462
# start(address, port = nil, helo: 'localhost', username: nil, secret: nil, authtype: nil, tls: false, starttls: :auto, tls_verify: true, tls_hostname: nil, ssl_context_params: nil) { |smtp| ... }
462
463
# start(address, port = nil, helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
463
464
#
@@ -520,6 +521,8 @@ def debug_output=(arg)
520
521
# These will be sent to #authenticate as positional arguments—the exact
521
522
# semantics are dependent on the +authtype+.
522
523
#
524
+ # +auth+ is a hash of arbitrary keyword arguments for #authenticate.
525
+ #
523
526
# See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
524
527
#
525
528
# === Errors
@@ -537,7 +540,7 @@ def debug_output=(arg)
537
540
#
538
541
def SMTP . start ( address , port = nil , *args , helo : nil ,
539
542
user : nil , secret : nil , password : nil , authtype : nil ,
540
- username : nil ,
543
+ username : nil , auth : nil ,
541
544
tls : false , starttls : :auto ,
542
545
tls_verify : true , tls_hostname : nil , ssl_context_params : nil ,
543
546
&block )
@@ -546,7 +549,8 @@ def SMTP.start(address, port = nil, *args, helo: nil,
546
549
username ||= user || args [ 1 ]
547
550
secret ||= password || args [ 2 ]
548
551
authtype ||= args [ 3 ]
549
- new ( address , port , tls : tls , starttls : starttls , tls_verify : tls_verify , tls_hostname : tls_hostname , ssl_context_params : ssl_context_params ) . start ( helo : helo , username : username , secret : secret , authtype : authtype , &block )
552
+ new ( address , port , tls : tls , starttls : starttls , tls_verify : tls_verify , tls_hostname : tls_hostname , ssl_context_params : ssl_context_params )
553
+ . start ( helo : helo , username : username , secret : secret , authtype : authtype , auth : auth , &block )
550
554
end
551
555
552
556
# +true+ if the \SMTP session has been started.
@@ -558,6 +562,7 @@ def started?
558
562
# :call-seq:
559
563
# start(helo: 'localhost', username: nil, secret: nil, authtype: nil) { |smtp| ... }
560
564
# start(helo = 'localhost', username = nil, secret = nil, authtype = nil) { |smtp| ... }
565
+ # start(helo = 'localhost', auth: {type: nil, **auth_kwargs}) { |smtp| ... }
561
566
#
562
567
# Opens a TCP connection and starts the SMTP session.
563
568
#
@@ -578,6 +583,8 @@ def started?
578
583
# These will be sent to #authenticate as positional arguments—the exact
579
584
# semantics are dependent on the +authtype+.
580
585
#
586
+ # +auth+ is an optional hash of keyword arguments for #authenticate.
587
+ #
581
588
# See the discussion of Net::SMTP@SMTP+Authentication in the overview notes.
582
589
#
583
590
# See also: Net::SMTP.start
@@ -619,13 +626,15 @@ def started?
619
626
# * Net::ReadTimeout
620
627
# * IOError
621
628
#
622
- def start ( *args , helo : nil , user : nil , secret : nil , password : nil , authtype : nil ,
623
- username : nil )
629
+ def start ( *args , helo : nil ,
630
+ user : nil , username : nil , secret : nil , password : nil ,
631
+ authtype : nil , auth : nil )
624
632
raise ArgumentError , "wrong number of arguments (given #{ args . size } , expected 0..4)" if args . size > 4
625
633
helo ||= args [ 0 ] || 'localhost'
626
634
username ||= user || args [ 1 ]
627
635
secret ||= password || args [ 2 ]
628
636
authtype ||= args [ 3 ]
637
+ auth ||= { }
629
638
if defined? ( OpenSSL ::VERSION )
630
639
ssl_context_params = @ssl_context_params || { }
631
640
unless ssl_context_params . has_key? ( :verify_mode )
@@ -640,13 +649,13 @@ def start(*args, helo: nil, user: nil, secret: nil, password: nil, authtype: nil
640
649
end
641
650
if block_given?
642
651
begin
643
- do_start helo , username , secret , authtype
652
+ do_start helo , username , secret , authtype , ** auth
644
653
return yield ( self )
645
654
ensure
646
655
do_finish
647
656
end
648
657
else
649
- do_start helo , username , secret , authtype
658
+ do_start helo , username , secret , authtype , ** auth
650
659
return self
651
660
end
652
661
end
@@ -664,9 +673,9 @@ def tcp_socket(address, port)
664
673
TCPSocket . open address , port
665
674
end
666
675
667
- def do_start ( helo_domain , user , secret , authtype )
676
+ def do_start ( helo_domain , user , secret , authtype , ** auth )
668
677
raise IOError , 'SMTP session already started' if @started
669
- check_auth_args authtype , user , secret
678
+ check_auth_args ( authtype , user , secret , ** auth )
670
679
s = Timeout . timeout ( @open_timeout , Net ::OpenTimeout ) do
671
680
tcp_socket ( @address , @port )
672
681
end
@@ -683,7 +692,11 @@ def do_start(helo_domain, user, secret, authtype)
683
692
# helo response may be different after STARTTLS
684
693
do_helo helo_domain
685
694
end
686
- authenticate user , secret , ( authtype || DEFAULT_AUTH_TYPE ) if user
695
+ if user or secret
696
+ authenticate ( user , secret , authtype , **auth )
697
+ elsif authtype or auth . any?
698
+ authenticate ( authtype , **auth )
699
+ end
687
700
@started = true
688
701
ensure
689
702
unless @started
0 commit comments