Module: Ronin::Support::Network::SMTP::Mixin
- Includes:
- Ronin::Support::Network::SSL::Mixin
- Included in:
- ESMTP::Mixin
- Defined in:
- lib/ronin/support/network/smtp/mixin.rb
Overview
Provides helper methods for communicating with SMTP services.
Constant Summary collapse
- DEFAULT_PORT =
Default SMTP port
25
Class Method Summary collapse
-
.message(**kwargs) {|email| ... } ⇒ String
Creates a properly formatted email.
Instance Method Summary collapse
-
#smtp_connect(host, user:, password:, port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login) {|smtp| ... } ⇒ Net::SMTP?
Creates a connection to the SMTP server.
-
#smtp_message(**kwargs) {|email| ... } ⇒ Email
Creates a new email message.
-
#smtp_send_message(host, user:, password:, port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login, from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) {|email| ... } ⇒ Object
Connects to an SMTP server and sends a message.
Methods included from Ronin::Support::Network::SSL::Mixin
#ssl_accept, #ssl_banner, #ssl_cert, #ssl_connect, #ssl_connect_and_send, #ssl_context, #ssl_open?, #ssl_send, #ssl_server, #ssl_server_loop, #ssl_server_session, #ssl_server_socket, #ssl_socket
Class Method Details
Instance Method Details
#smtp_connect(host, user:, password:, port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login) {|smtp| ... } ⇒ Net::SMTP?
Creates a connection to the SMTP server.
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 169 170 171 172 173 174 175 |
# File 'lib/ronin/support/network/smtp/mixin.rb', line 144 def smtp_connect(host, user: , password: , port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login) host = DNS::IDN.to_ascii(host) user = user.to_s password = password.to_s case ssl when Hash ssl = true context = ssl_context(ssl) when TrueClass ssl = true context = ssl_context end smtp = Net::SMTP.new(host,port) smtp.enable_starttls(context) if ssl smtp.start(helo,user,password,auth) if block_given? begin yield smtp ensure smtp.finish end else return smtp end end |
#smtp_message(**kwargs) {|email| ... } ⇒ Email
Creates a new email message.
88 89 90 |
# File 'lib/ronin/support/network/smtp/mixin.rb', line 88 def (**kwargs,&block) Email.new(**kwargs,&block) end |
#smtp_send_message(host, user:, password:, port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login, from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil) {|email| ... } ⇒ Object
Connects to an SMTP server and sends a message.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ronin/support/network/smtp/mixin.rb', line 258 def (host, user: , password: , # smtp options port: DEFAULT_PORT, ssl: nil, helo: 'localhost', auth: :login, # email options from: nil, to: nil, subject: nil, date: Time.now, message_id: nil, headers: nil, body: nil, &block) email = ( to: to, subject: subject, date: date, message_id: , headers: headers, body: body, &block ) smtp_connect(host,user,password, port: port, ssl: ssl, helo: helo, auth: auth) do |smtp| smtp.(email.to_s, email.from, email.to) end end |