Error sending simple email with python

0

I'm learning to send emails with python. Right at the beginning, I came across error importing the smtplib module methods, which generated this question:

Import error when sending simple email with python

Then I saw that it did not give an import error when typing command by command on the python command line. But another error occurred. These are the commands I type line by line:

from smtplib import SMTP_SSL
server=SMTP_SSL('smtp.live.com',465)

In this second line, the following error occurs:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    server=SMTP_SSL('smtp.live.com',465)
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 1021, in __init__
    source_address)
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 335, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\smtplib.py", line 1027, in _get_socket
    self.source_address)
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 711, in create_connection
    raise err
  File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 702, in create_connection
    sock.connect(sa)
OSError: [WinError 10013] Foi feita uma tentativa de acesso a um soquete de uma maneira que é proibida pelas permissões de acesso

How do I fix this error? Does anyone have any scrit that works that sends email with python?

    
asked by anonymous 29.12.2016 / 16:38

1 answer

1

As this answer in SOen is because in Windows you need the UAC administrator privilege, to solve this click right click on cmd.exe and select the Run as Administrator option and then try to run the script:

python enviaremail.py

The prompt should show this:

If it still fails, it may not be the privileges, but an antivirus that blocks this method because it is mass mailing. I noticed that you also installed Python in the user folder instead of the Programs And Files folder, maybe this will prevent some access (check that python.exe is enabled in Firewall as well)

    
29.12.2016 / 17:47