@@ -274,11 +274,14 @@ def capable_starttls?
274
274
capable? ( 'STARTTLS' )
275
275
end
276
276
277
+ # true if the EHLO response contains +key+.
277
278
def capable? ( key )
278
279
return nil unless @capabilities
279
280
@capabilities [ key ] ? true : false
280
281
end
281
- private :capable?
282
+
283
+ # The server capabilities by EHLO response
284
+ attr_reader :capabilities
282
285
283
286
# true if server advertises AUTH PLAIN.
284
287
# You cannot get valid value before opening SMTP session.
@@ -703,9 +706,9 @@ def do_finish
703
706
# binary message with this method. +msgstr+ should include both
704
707
# the message headers and body.
705
708
#
706
- # +from_addr+ is a String representing the source mail address.
709
+ # +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
707
710
#
708
- # +to_addr+ is a String or Strings or Array of Strings , representing
711
+ # +to_addr+ is a String or Net::SMTP::Address or Array of them , representing
709
712
# the destination mail address or addresses.
710
713
#
711
714
# === Example
@@ -716,6 +719,12 @@ def do_finish
716
719
717
720
# end
718
721
#
722
+ # Net::SMTP.start('smtp.example.com') do |smtp|
723
+ # smtp.send_message msgstr,
724
+ # Net::SMTP::Address.new('[email protected] ', size: 12345),
725
+ # Net::SMTP::Address.new('[email protected] ', notify: :success)
726
+ # end
727
+ #
719
728
# === Errors
720
729
#
721
730
# This method may raise:
@@ -752,9 +761,9 @@ def send_message(msgstr, from_addr, *to_addrs)
752
761
#
753
762
# === Parameters
754
763
#
755
- # +from_addr+ is a String representing the source mail address.
764
+ # +from_addr+ is a String or Net::SMTP::Address representing the source mail address.
756
765
#
757
- # +to_addr+ is a String or Strings or Array of Strings , representing
766
+ # +to_addr+ is a String or Net::SMTP::Address or Array of them , representing
758
767
# the destination mail address or addresses.
759
768
#
760
769
# === Example
@@ -904,8 +913,10 @@ def ehlo(domain)
904
913
getok ( "EHLO #{ domain } " )
905
914
end
906
915
916
+ # +from_addr+ is +String+ or +Net::SMTP::Address+
907
917
def mailfrom ( from_addr )
908
- getok ( "MAIL FROM:<#{ from_addr } >" )
918
+ addr = Address . new ( from_addr )
919
+ getok ( ( [ "MAIL FROM:<#{ addr . address } >" ] + addr . parameters ) . join ( ' ' ) )
909
920
end
910
921
911
922
def rcptto_list ( to_addrs )
@@ -916,7 +927,7 @@ def rcptto_list(to_addrs)
916
927
begin
917
928
rcptto addr
918
929
rescue SMTPAuthenticationError
919
- unknown_users << addr . dump
930
+ unknown_users << addr . to_s . dump
920
931
else
921
932
ok_users << addr
922
933
end
@@ -929,8 +940,10 @@ def rcptto_list(to_addrs)
929
940
ret
930
941
end
931
942
943
+ # +to_addr+ is +String+ or +Net::SMTP::Address+
932
944
def rcptto ( to_addr )
933
- getok ( "RCPT TO:<#{ to_addr } >" )
945
+ addr = Address . new ( to_addr )
946
+ getok ( ( [ "RCPT TO:<#{ addr . address } >" ] + addr . parameters ) . join ( ' ' ) )
934
947
end
935
948
936
949
# This method sends a message.
@@ -1139,6 +1152,33 @@ def logging(msg)
1139
1152
@debug_output << msg + "\n " if @debug_output
1140
1153
end
1141
1154
1155
+ # Address with parametres for MAIL or RCPT command
1156
+ class Address
1157
+ # mail address [String]
1158
+ attr_reader :address
1159
+ # paramters [Array<String>]
1160
+ attr_reader :parameters
1161
+
1162
+ # :call-seq:
1163
+ # initialize(address, parameter, ...)
1164
+ #
1165
+ # address +String+ or +Net::SMTP::Address+
1166
+ # parameter +String+ or +Hash+
1167
+ def initialize ( address , *args , **kw_args )
1168
+ if address . kind_of? Address
1169
+ @address = address . address
1170
+ @parameters = address . parameters
1171
+ else
1172
+ @address = address
1173
+ @parameters = ( args + [ kw_args ] ) . map { |param | Array ( param ) } . flatten ( 1 ) . map { |param | Array ( param ) . compact . join ( '=' ) }
1174
+ end
1175
+ end
1176
+
1177
+ def to_s
1178
+ @address
1179
+ end
1180
+ end
1181
+
1142
1182
end # class SMTP
1143
1183
1144
1184
SMTPSession = SMTP # :nodoc:
0 commit comments