0

where is problem ? i want check server with proxy list but the code errors out:

__init__() got an unexpected keyword argument 'proxies'

If i exclude the proxy key-word argument, it is working fine.

import  os, sys, smtplib
with open('proxy.txt') as urls:
    for line in urls:
        proxies=line.rstrip()
        file = open('sever.txt', 'r') # contains <server>:<user>:<pass>:<port>

        for line in file.readlines():
            list1 = line.split(':')

            try:
                server=smtplib.SMTP(list1[0]+':'+list1[3], proxies={"https":proxies})
                server.starttls()
                server.login(list1[1],list1[2])
                server.quit()
                with open ("valid.txt", "a") as f:
                    f.write(str (list1[0]+":"+list1[1]))

            except Exception as e:
                print e
Karan
  • 1,335
  • 2
  • 14
  • 29
alex
  • 1
  • 2

2 Answers2

0

Thanks for providing the error message and it is now clear what is happening - proxies is not a valid parameter to the smtplib. Hence you get the __init__() error meaning it cannot initialize the Object with the given parameters.

If you wish to send emails through a proxy, I recommend reading through Python smtplib proxy support

using socks or any other python socket config package, you can set proxy settings before instantiating the SMTP client.

from Python send email behind a proxy server:

#socks.setdefaultproxy(TYPE, ADDR, PORT)
socks.setdefaultproxy(socks.SOCKS5, 'proxy.proxy.com', 8080)
socks.wrapmodule(smtplib)
Karan
  • 1,335
  • 2
  • 14
  • 29
  • how can i use proxy list ? and use random pick proxy ? – alex Nov 13 '20 at 23:13
  • a simple, naive way to do this is: in your `for` loop, in each iteration, you can run the two `socks` methods i have above and keep re-wrapping your smtlib module on a new proxy in each iteration. – Karan Nov 13 '20 at 23:17
0

now i have problem there my proxy list 2 line server list 10 line after 2 request code stopped :(

import  os, sys, smtplib
import socks
with open('proxy.txt') as urls:
    for line in urls:
        proxies=line.rstrip()
        try:
            socks.setdefaultproxy(socks.HTTP, proxies, 8080)
            socks.wrapmodule(smtplib)
            file = open('server.txt', 'r')
            for line in file.readlines():
                list1 = line.split(':')

            
            server=smtplib.SMTP(list1[0]+':'+list1[3])
            server.starttls()
            server.login(list1[1],list1[2])
            server.quit()
            print "valid   "+proxies+"   "+list1[1]
            with open ("valid.txt", "a") as f:
                f.write(str (list1[0]+":"+list1[1])+'\n')

        except:
            print "bad   "+proxies+"   "+list1[1]
alex
  • 1
  • 2
  • what do you mean stopped? Is there an exception being thrown? (don't swallow your exceptions. you should at least be doing this: `except Exception as e: print(e)` – Karan Nov 14 '20 at 00:12