Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Net::SMTP over SOCKS proxy?

I'm doing this, in Ruby 2.6:

require 'net/smtp'
Net::SMTP.start('smtp.gmail.com', 457).do |smtp|
  smtp.helo('gmail.com')
end

Now I want to do exactly the same, but over SOCKS4/5 proxy. I can't find anything in the documentation.

like image 468
yegor256 Avatar asked Nov 24 '25 08:11

yegor256


1 Answers

Looking at the source of Net::SMTP it would seem like it doesn't have built-in support for SOCKS proxies.

A couple of ideas:

  1. Is your Ruby interpreter built with SOCKS support? If yes, then you'd be able to use SOCKSSocket class. Create a subclass of Net::SMTP and override tcp_socket method to use SOCKSSocket instead of TCPSocket.
  2. Use ruby-proxifier gem (although it seems rather old).
  3. Re-implement SOCKSSocket in pure Ruby (connecting through SOCKS4 isn't too hard, SOCKS5 is slightly more complicated, see this example for reference) or find an existing implementation (although I haven't been able to find one).
like image 102
eyevan Avatar answered Nov 25 '25 20:11

eyevan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!