import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def sendmail(from_email, password, to_email, subject, message):
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
try:
server = smtplib.SMTP_SSL('smtp.outlook.com', 465)
server.ehlo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close()
return True
except Exception as e:
print('Something went wrong: ' + str(e))
return False
sendmail('myname@mycompanyname.com.tr', 'mypassword', 'myworkmatename@mycompanyname.com.tr', 'TEST', 'I send a mail to you with Python')
我收到此错误:
[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我看到了一些有关代理设置的解决方案,但对我来说不起作用。我该如何解决?