无法在python中使用exchangelib连接Microsoft Exchange邮件服务器

问题描述 投票:0回答:1

我正在尝试使用 python 中的 Exchangelib 库连接我的官方邮件服务器并收到错误

“HTTPConnectionPool(主机='mail.domainnam.in',端口=443):读取超时。(读取超时=120)”

def send_mail(content):
    # Load environment variables from the .env file
    load_dotenv()

    # Access environment variables
    outlook_user = os.getenv('OUTLOOK_USER')
    outlook_password = os.getenv('OUTLOOK_PASS')
    outlook_server = os.getenv('OUTLOOK_SERVER')
    outlook_email = os.getenv('OUTLOOK_EMAIL')

    credentials = Credentials(
        username=outlook_user,
        password=outlook_password
        )

    config = Configuration(
        server=outlook_server,
        credentials=credentials
        )

    account = Account(
        primary_smtp_address=outlook_email,
        config=config,
        autodiscover=False,
        access_type=DELEGATE
        )

    msg = Message(
        account=account,
        subject="Test Mail",
        body=content,
        to_recipients=["email_address_1"],
        cc_recipients=["email_address_2"]
        )
    msg.send_and_save()

我已经尝试过这个线程,但没有一个解决方案有效“https://github.com/ecederstrand/exchangelib/issues/271”

请帮忙。

python python-3.x exchange-server office-automation exchangelib
1个回答
0
投票

调整 Exchangelib 代码中的超时设置。

config = Configuration(
    server=outlook_server,
    credentials=credentials,
    timeout=30  # Adjust the timeout duration as needed
)
© www.soinside.com 2019 - 2024. All rights reserved.