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(params = {}) ⇒ SMTP
constructor
– initialize ++.
-
#send_mail(subject, message, params = {}) ⇒ Object
– send_mail ++.
Constructor Details
#initialize(params = {}) ⇒ SMTP
– initialize ++
16 17 18 19 20 |
# File 'lib/easysuite/smtp.rb', line 16 def initialize(params = {}) @port = Net::SMTP.default_port @helo_domain = "localhost" Config.set_values(self, params) 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
#send_mail(subject, message, params = {}) ⇒ Object
– send_mail ++
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 55 56 57 58 59 60 61 62 |
# File 'lib/easysuite/smtp.rb', line 25 def send_mail(subject, , params = {}) params = params.dup params[:from] ||= @from params[:to] ||= @to params[:cc] ||= @cc params[:bcc] ||= @bcc 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 = [] ["From", "To", "Cc", "Bcc"].each do |key| next unless value = params[key.downcase.to_sym] headers << make_header(key, value) end 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(params), rcpt_to(params)) end end |