python - 在python中的azure databricks笔记本中发送电子邮件(outlook作为服务器)?

标签 python azure smtp office365 databricks

我尝试使用本地主机进行配置。我在我的命令行中运行了这个。 (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.

您可以引用Send emails from Azure Databricks

关于python - 在python中的azure databricks笔记本中发送电子邮件(outlook作为服务器)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72259504/

相关文章:

python - Django-Celery:未创建 djkombu_queue 表

azure - Docker 容器 VS PCF

wcf - 如何在 Azure 中的 Web 角色的外部和内部终结点上托管 WCF 服务?

PHPMailer,Gmail 的 SMTP connect() 失败错误

java - 我需要为多个收件人发送邮件

python - 如何控制Python格式字符串中科学计数法的准确格式?

python - 我可以将 wtforms DateTimeField 设置为也只接受日期值吗?

azure - 无法更改 Azure ML 笔记本中的虚拟环境

python - 通过smtplib发送邮件时如何在邮件内容中添加href链接

python - 在Python中,我们如何将某个变量的先前值存储在另一个变量中?