Class: Envoy::Email
Instance Attribute Summary collapse
-
#authentication ⇒ Object
Returns the value of attribute authentication.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#host ⇒ Object
Returns the value of attribute host.
-
#openssl_verify_mode ⇒ Object
Returns the value of attribute openssl_verify_mode.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#to ⇒ Object
Returns the value of attribute to.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Transport
Instance Method Summary collapse
- #build_connection ⇒ Object
- #build_mail(message) ⇒ Object
-
#initialize(options = {}) ⇒ Email
constructor
A new instance of Email.
- #send_message(message) ⇒ Object
- #sendmail_binary ⇒ Object
- #tls_mode ⇒ Object
- #using_authentication? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Email
Returns a new instance of Email.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/envoy/transport.rb', line 95 def initialize( = {}) self.host = [:host] self.username = [:username] self.sender = [:sender] self.password = [:password] self.to = [:to] self.port = [:port] || 25 self.ssl = [:ssl] || false self.authentication = [:authentication] || nil self.domain = [:domain] self.openssl_verify_mode = [:openssl_verify_mode] end |
Instance Attribute Details
#authentication ⇒ Object
Returns the value of attribute authentication.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def authentication @authentication end |
#domain ⇒ Object
Returns the value of attribute domain.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def domain @domain end |
#host ⇒ Object
Returns the value of attribute host.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def host @host end |
#openssl_verify_mode ⇒ Object
Returns the value of attribute openssl_verify_mode.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def openssl_verify_mode @openssl_verify_mode end |
#password ⇒ Object
Returns the value of attribute password.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def port @port end |
#sender ⇒ Object
Returns the value of attribute sender.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def sender @sender end |
#ssl ⇒ Object
Returns the value of attribute ssl.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def ssl @ssl end |
#to ⇒ Object
Returns the value of attribute to.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def to @to end |
#username ⇒ Object
Returns the value of attribute username.
93 94 95 |
# File 'lib/envoy/transport.rb', line 93 def username @username end |
Instance Method Details
#build_connection ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/envoy/transport.rb', line 124 def build_connection smtp = Net::SMTP.new(@host, @port) if using_authentication? @openssl_verify_mode.nil? ? smtp.send(tls_mode) : smtp.send(tls_mode, @openss_verify_mode) end return smtp end |
#build_mail(message) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/envoy/transport.rb', line 113 def build_mail() mail = TMail::Mail.new mail.to = @to.is_a?(String) ? @to : @to.join(',') mail.from = @sender.nil? ? 'Envoy Messenger <envoymessenger@localhost>' : @sender mail.subject = .subject mail.date = Time.now mail.body = .body || .subject mail end |
#send_message(message) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/envoy/transport.rb', line 142 def () mail = self.build_mail() if @host.to_sym == :sendmail IO.popen("#{self.sendmail_binary} -f #{mail.from}, #{mail.to}", "w+") do |io| io.puts mail io.flush end else smtp = build_connection if using_authentication? smtp.start(@domain, @username, @password, @authentication.to_sym) do |smtp| smtp.sendmail mail.to_s, mail.from, mail.to end else smtp.start do |smtp| smtp.sendmail mail.to_s, mail.from, mail.to end end end return true rescue StandardError => error self.errors << SendError.new(error, Time.now) return false end |
#sendmail_binary ⇒ Object
108 109 110 111 |
# File 'lib/envoy/transport.rb', line 108 def sendmail_binary sendmail = `which sendmail`.chomp (sendmail.nil? || sendmail == '') ? '/usr/bin/sendmail' : sendmail end |
#tls_mode ⇒ Object
134 135 136 |
# File 'lib/envoy/transport.rb', line 134 def tls_mode RUBY_VERSION <= '1.8.6' ? "enable_tls" : "enable_starttls_auto" end |
#using_authentication? ⇒ Boolean
138 139 140 |
# File 'lib/envoy/transport.rb', line 138 def using_authentication? !@username.nil? && !@password.nil? && !@authentication.nil? && @ssl end |