Reputation: 1124
I was trying to build a python script which could send emails via Gmail.
When I try to connect to the Gmail Server, I get an error Errno 10013
.
This is what I'm trying to do:
gmail_message = smtplib.SMTP('smtp.gmail.com')
gmail_message.starttls()
gmail_message.login('[email protected]','xyzpassword')
gmail_message.sendmail('[email protected]',['[email protected]'], msg.as_string())
gmail_message.quit()
Error:
error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
What can I do to fix this?
Upvotes: 2
Views: 1759
Reputation: 2828
This is code that worked for me on Win7. It's pretty much identical to yours.
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
for comp in comps:
msg = "Subject:CommenceSweep:Comp%s-%s\n\n" % (comp,sweep)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
Note: Did you correctly configure Gmail to allow SMTP?
Upvotes: 0
Reputation: 1794
You may need to specify the port by
gmail_message = smtplib.SMTP(host='smtp.gmail.com', port=587)
Upvotes: 1