Error sending simple email with python

Asked

Viewed 779 times

0

I am learning to send emails with python. Early on, I came across an import error of the methods of the smtplib module, which generated this question:

Import error when sending simple email with python

Then I saw that there was no import error when typing command by command on the python command line. However, another error occurred. These are the commands I type line by line:

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

On 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?

1 answer

1

According to this reply on Soen is because Windows requires the UAC administrator privilege, to resolve this right-click cmd.exe and select the option Run as Administrator and then try to run the script:

python enviaremail.py

The prompt should show this:

prompt

If it still fails, it may not be the privileges, but an Antivirus that blocks this method because it is sent in bulk. I noticed that you also installed Python in the user folder instead of the folder Programs And Files, maybe this prevents some access (check if python.exe is released in Firewall as well)

  • Unfortunately, the administrator permission did not fix the problem. I disabled Antivirus and also got no result. Python

  • @Benedito how is windows update? Tried to reinstall Python in the "program files" (Programs And Files) as I mentioned?

  • I installed Python by default, so he put himself in this folder. But I’ve been using it for a while and it never bothered him to be in this folder. And it is released by Firewall as well. In fact, I was able to send e-mail via TLS, using the smtplib.SMTP.method. Only this smtplib.SMTP_SSL is giving error.

  • Automatic updates always active, to download and install.

  • @Benedito I am almost sure that the address smtp.live.com only accepts TLS and not SSL.

  • And you know some that’s accepted?

  • @Benedito I believe that most today use the TLS, but for the sake of conscience it would be nice to check if your Python has SSL installed.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.