summaryrefslogtreecommitdiff
path: root/lib/net/smtp.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/net/smtp.rb')
-rw-r--r--lib/net/smtp.rb45
1 files changed, 31 insertions, 14 deletions
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 5331ee17e7..dfb27660fd 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -37,7 +37,7 @@ executed.
require 'net/smtp'
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
- # use smtp object only in this block
+ # use smtp object only in this block
}
Replace 'your.smtp.server' by your SMTP server. Normally
@@ -49,7 +49,7 @@ Then you can send mail.
require 'net/smtp'
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
- smtp.send_mail <<EndOfMail, '[email protected]', '[email protected]'
+ smtp.send_mail <<EndOfMail, '[email protected]', '[email protected]'
From: Your Name <[email protected]>
To: Dest Address <[email protected]>
Subject: test mail
@@ -60,6 +60,23 @@ Then you can send mail.
EndOfMail
}
+=== Closing Session
+
+You MUST close SMTP session after sending mails, by calling #finish
+method. You can also use block form of SMTP.start/SMTP#start, which
+closes session automatically. I strongly recommend later one. It is
+more beautiful and simple.
+
+ # using SMTP#finish
+ smtp = Net::SMTP.start( 'your.smtp.server', 25 )
+ smtp.send_mail mail_string, 'from@address', 'to@address'
+ smtp.finish
+
+ # using block form of SMTP.start
+ Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
+ smtp.send_mail mail_string, 'from@address', 'to@address'
+ }
+
=== Sending Mails from Any Sources
In an example above I sent mail from String (here document literal).
@@ -68,9 +85,9 @@ like File and Array.
require 'net/smtp'
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
- File.open( 'Mail/draft/1' ) {|f|
- smtp.send_mail f, '[email protected]', '[email protected]'
- }
+ File.open( 'Mail/draft/1' ) {|f|
+ smtp.send_mail f, '[email protected]', '[email protected]'
+ }
}
=== Giving "Hello" Domain
@@ -99,7 +116,7 @@ send or reject SMTP session by this data.
# example
Net::SMTP.start( 'your.smtp.server' ) {
- smtp.send_mail mail_string, '[email protected]', '[email protected]'
+ smtp.send_mail mail_string, '[email protected]', '[email protected]'
}
=== Instance Methods
@@ -153,9 +170,9 @@ send or reject SMTP session by this data.
# example
Net::SMTP.start( 'your.smtp.server' ) {|smtp|
- smtp.send_mail mail_string,
+ smtp.send_mail mail_string,
}
: ready( from_addr, *to_addrs ) {|adapter| .... }
@@ -169,11 +186,11 @@ send or reject SMTP session by this data.
# example
Net::SMTP.start( 'your.smtp.server', 25 ) {|smtp|
- smtp.ready( '[email protected]', '[email protected]' ) do |adapter|
- adapter.write str1
- adapter.write str2
- adapter.write str3
- end
+ smtp.ready( '[email protected]', '[email protected]' ) do |adapter|
+ adapter.write str1
+ adapter.write str2
+ adapter.write str3
+ end
}
== Exceptions