try:
server = smtplib.SMTP('smtp.gmail.com',587)
print("Initializing....")
server.starttls()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, msg.as_string())
server.close()
print 'Email sent!'
except smtplib.SMTPException as e:
print 'Something went wrong...'
print (str(e))
当我在mac上使用它时,此代码会发送电子邮件。 它会在Windows 10上抛出错误:
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
此外,telnet smtp.gmail.com 587适用于Windows 10机器。
Windows计算机上未安装防病毒软件。