我尝试使用本地主机进行配置。我在我的命令行中运行了这个。 (python -m smtpd -c 调试服务器 -n localhost:1025)
import smtplib, ssl
smtp_server = "localhost"
port = 1025 # For starttls
sender_email = "my outlook email"
password = input("Type your password and press enter: ")
# Create a secure SSL context
context = ssl.create_default_context()
# Try to log in to server and send email
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo() # Can be omitted
server.starttls(context=context) # Secure the connection
server.ehlo() # Can be omitted
server.login(sender_email, password)
print("server connected")
# TODO: Send email here
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()
但它给出“连接被拒绝”错误。
最佳答案
要解决连接被拒绝
错误,您可以尝试以下方法:
- 防火墙可能阻止访问端口 1025
- 或者,您可以尝试 using port 25
根据documentation :
For Enterprise Dev/Test subscriptions, port 25 is blocked by default. It is possible to have this block removed. To request to have the block removed, go to the Cannot send email (SMTP-Port 25) section of the Diagnose and Solve blade in the Azure Virtual Network resource in the Azure portal and run the diagnostic. This will exempt the qualified enterprise dev/test subscriptions automatically.
关于python - 在python中的azure databricks笔记本中发送电子邮件(outlook作为服务器)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72259504/