Method: Net::SMTP#data
- Defined in:
- lib/net/smtp.rb
#data(msgstr = nil, &block) ⇒ Object
This method sends a message. If msgstr is given, sends it as a message. If block is given, yield a message writer stream. You must write message before the block is closed.
# Example 1 (by string)
smtp.data("From: [email protected]\nTo: [email protected]\nSubject: I found a bug\n\nCheck vm.c:58879.\n")
# Example 2 (by block)
smtp.data {|f|
f.puts "From: [email protected]"
f.puts "To: [email protected]"
f.puts "Subject: I found a bug"
f.puts ""
f.puts "Check vm.c:58879."
}
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 |
# File 'lib/net/smtp.rb', line 885 def data(msgstr = nil, &block) #:yield: stream if msgstr and block raise ArgumentError, "message and block are exclusive" end unless msgstr or block raise ArgumentError, "message or block is required" end res = critical { check_continue get_response('DATA') socket_sync_bak = @socket.io.sync begin @socket.io.sync = false if msgstr @socket. msgstr else @socket.(&block) end ensure @socket.io.flush @socket.io.sync = socket_sync_bak end recv_response() } check_response res res end |