How can I send emails via proxy ? I have read some topics on the forum, but there is no clear answer anywhere.
my_message -> proxy_server_socks5 -> SMTP server -> Recipient
I tried to do it like this:
import smtplib
import socks
#socks.setdefaultproxy(TYPE, ADDR, PORT)
socks.setdefaultproxy(socks.SOCKS5, 'socks5://login:password@127.0.0.1', 8000)
socks.wrapmodule(smtplib)
smtpserver = 'smtp.example.com'
AUTHREQUIRED = 1
smtpuser = 'example@mail.com'
smtppass = 'password'
RECIPIENTS = 'recipient@mail.com'
SENDER = 'example@mail.com'
mssg = "test message"
s = mssg
server = smtplib.SMTP(smtpserver,465)
server.ehlo()
server.starttls()
server.ehlo()
server.login(smtpuser,smtppass)
server.set_debuglevel(1)
server.sendmail(SENDER, [RECIPIENTS], s)
server.quit()
But I get this error:
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy socks5://login:password@127.0.0.1:8000: [Errno 11003] getaddrinfo failed
Of course, I specified the ip and port for an example, in the script I have the real data