Class: Keystone::Mail::Send
Instance Attribute Summary collapse
-
#message ⇒ Object
Returns the value of attribute message.
-
#retry_cnt ⇒ Object
Returns the value of attribute retry_cnt.
-
#smtp_addr ⇒ Object
Returns the value of attribute smtp_addr.
-
#smtp_port ⇒ Object
Returns the value of attribute smtp_port.
Class Method Summary collapse
-
.send(from, to, subject, body, opt = {}) ⇒ Object
from could be String or Array opt :smtp_addr :smtp_port :retry :mail_from_text :encoding.
Instance Method Summary collapse
-
#initialize(message = nil, opt = {}) ⇒ Send
constructor
普通なことをしたいならTMailを使いましょう class Send.
- #send ⇒ Object
- #set_option(opt) ⇒ Object
Constructor Details
#initialize(message = nil, opt = {}) ⇒ Send
普通なことをしたいならTMailを使いましょう
class Send
16 17 18 19 20 21 22 |
# File 'lib/keystone/mail/send.rb', line 16 def initialize(=nil,opt={}) @smtp_addr, @smtp_port, @retry_cnt = "127.0.0.1", 25, 0 @message = @message = Keystone::Mail::MessageFactory.create(opt) if @message == nil debug "@message=#{@message}" set_option(opt) end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
11 12 13 |
# File 'lib/keystone/mail/send.rb', line 11 def @message end |
#retry_cnt ⇒ Object
Returns the value of attribute retry_cnt.
11 12 13 |
# File 'lib/keystone/mail/send.rb', line 11 def retry_cnt @retry_cnt end |
#smtp_addr ⇒ Object
Returns the value of attribute smtp_addr.
11 12 13 |
# File 'lib/keystone/mail/send.rb', line 11 def smtp_addr @smtp_addr end |
#smtp_port ⇒ Object
Returns the value of attribute smtp_port.
11 12 13 |
# File 'lib/keystone/mail/send.rb', line 11 def smtp_port @smtp_port end |
Class Method Details
.send(from, to, subject, body, opt = {}) ⇒ Object
from could be String or Array opt
:smtp_addr
:smtp_port
:retry
:mail_from_text
:encoding
33 34 35 36 37 38 39 40 |
# File 'lib/keystone/mail/send.rb', line 33 def self.send(from, to, subject, body, opt={}) queue = self.new(nil,opt) queue..mail_to = to queue..mail_from = from queue..subject = subject queue..body = body queue.send end |
Instance Method Details
#send ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/keystone/mail/send.rb', line 42 def send src = @message.to_src debug src try_cnt = 0 begin m = Net::SMTPSession.new(@smtp_addr, @smtp_port) m.start() m.sendmail(src ,@message.mail_from ,@message.mail_to) m.finish rescue => e debug "try_cnt:#{try_cnt}" try_cnt += 1 sleep 1 retry if @retry_cnt >= try_cnt raise e end end |
#set_option(opt) ⇒ Object
60 61 62 63 64 |
# File 'lib/keystone/mail/send.rb', line 60 def set_option(opt) @smtp_addr = opt[:smtp_addr] if opt.key?(:smtp_addr) @smtp_port = opt[:smtp_port] if opt.key?(:smtp_port) @retry_cnt = Integer(opt[:retry_cnt]) if opt.key?(:retry_cnt) end |