1

I have been experimenting with smptlib and am trying to sen a email to somebody. Here is my code:

import smtplib
my_email = "sender_email@gmail.com"
my_password = "password1234"
connection = smtplib.SMTP("smtp.gmail.com")
connection.starttls()
connection.login(user=my_email, password=my_password)
connection.sendmail(from_addr=my_email, to_addrs="receiver_email@gmail.com", msg="Hello")
connection.quit()

The sender's email, sender's password, and receiver's email are not valid, for privacy reasons. I do, however keep getting this error:

PermissionError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

It may help you to know that I am using the latest version of PyCharm IDE and the latest version of smtplib. My question is: Why am I continually getting this error?

I tried fiddling around, and I think that the code:

connection = smtplib.SMTP("smpt.gmail.com")

was the problem. I think. I also have tried putting in examples and other people's code, but I get the same PermissionError as always.

VPfB
  • 14,927
  • 6
  • 41
  • 75
bchyou
  • 11
  • 2
  • Does this answer your question? [socket.error: \[Errno 10013\] An attempt was made to access a socket in a way forbidden by its access permissions](https://stackoverflow.com/questions/2778840/socket-error-errno-10013-an-attempt-was-made-to-access-a-socket-in-a-way-forb) – Nir Alfasi Apr 15 '23 at 17:14
  • No, unfortunately not. But thanks! – bchyou Apr 15 '23 at 17:15
  • It is possible that gmail doesn't support the connection type that you are trying. Please do an SSL connection instead using the following command `connection = smtplib.SMTP_SSL('smtp.gmail.com', 465)`. Also this webpage has a tutorial on how to send email using gmail in Python: https://mailtrap.io/blog/python-send-email-gmail/ – Nimar Apr 18 '23 at 22:34

0 Answers0