Class: EasySuite::SMTP
- Inherits:
-
Object
- Object
- EasySuite::SMTP
- Defined in:
- lib/easysuite/smtp.rb
Overview
– SMTP ++ Class to send mail easily.
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#address ⇒ Object
Returns the value of attribute address.
-
#authtype ⇒ Object
Returns the value of attribute authtype.
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#cc ⇒ Object
Returns the value of attribute cc.
-
#from ⇒ Object
Returns the value of attribute from.
-
#helo_domain ⇒ Object
Returns the value of attribute helo_domain.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize ⇒ SMTP
constructor
– initialize ++.
-
#mail_from ⇒ Object
– mail_from ++.
-
#rcpt_to ⇒ Object
– rcpt_to ++.
-
#send_mail(subject, message) ⇒ Object
– send_mail ++.
Constructor Details
#initialize ⇒ SMTP
– initialize ++
16 17 18 19 |
# File 'lib/easysuite/smtp.rb', line 16 def initialize @port = Net::SMTP.default_port @helo_domain = "localhost" end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def account @account end |
#address ⇒ Object
Returns the value of attribute address.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def address @address end |
#authtype ⇒ Object
Returns the value of attribute authtype.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def authtype @authtype end |
#bcc ⇒ Object
Returns the value of attribute bcc.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def bcc @bcc end |
#cc ⇒ Object
Returns the value of attribute cc.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def cc @cc end |
#from ⇒ Object
Returns the value of attribute from.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def from @from end |
#helo_domain ⇒ Object
Returns the value of attribute helo_domain.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def helo_domain @helo_domain end |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def port @port end |
#to ⇒ Object
Returns the value of attribute to.
10 11 12 |
# File 'lib/easysuite/smtp.rb', line 10 def to @to end |
Instance Method Details
#mail_from ⇒ Object
– mail_from ++
59 60 61 |
# File 'lib/easysuite/smtp.rb', line 59 def mail_from extract_address(@from) end |
#rcpt_to ⇒ Object
– rcpt_to ++
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/easysuite/smtp.rb', line 66 def rcpt_to addrs = [] ([@to].flatten + [@cc].flatten + [@bcc].flatten).each do |addr| next unless addr addrs << extract_address(addr) end addrs.uniq end |
#send_mail(subject, message) ⇒ Object
– send_mail ++
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/easysuite/smtp.rb', line 24 def send_mail(subject, ) smtp = Net::SMTP.new(@address, @port) case @port when Net::SMTP.default_port when Net::SMTP.default_tls_port smtp.enable_tls when Net::SMTP.default_submission_port smtp.enable_starttls else raise "Not supported port: #{@port}" end body, charset, transfer_encoding = make_body() headers = [] headers << make_header("From", @from) if @from headers << make_header("To", @to) if @to headers << make_header("Cc", @cc) if @cc headers << make_header("Bcc", @bcc) if @bcc headers << make_header("Subject", subject) headers << make_header("Date", Time.now.strftime("%a, %d %b %Y %X %z")) headers << make_header("Mime-Version", "1.0") headers << make_header("Content-Type", "text/plain; charset=#{charset}") headers << make_header("Content-Transfer-Encoding", transfer_encoding) mailsrc = headers.join("\n") mailsrc += "\n\n#{body}" smtp.start(@helo_domain, @account, @password, @authtype) do |smtp| smtp.send_mail(mailsrc, mail_from, rcpt_to) end end |