Azure 电子邮件轮询器卡在“进行中”

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

我正在使用

azure-communication-email
python 包从 Databricks 集群发送电子邮件。该脚本在旧版本中运行良好,但他们最近推出了新版本(2023 年 7 月 3 日的版本 1.0.0b2),它使用了不同的创作风格。

from azure.communication.email import EmailClient
email_client = EmailClient.from_connection_string(comm_connection_string)
display_name = make_user_display_name(username)
message = {
    "content": {
        "subject": f"Subject",
        "plainText": f"email body here",
    },
        "recipients": {
            "to": [
                {
                    "address": username,
                    "displayName": display_name
                }
            ]
},
    "senderAddress": "[email protected]",
    "attachments": [
        {
            "name":save_name,
            "contentType": "txt",
            "contentInBase64": file_bytes_b64.decode()
        }
    ]
}
poller = email_client.begin_send(message)
result = poller.result()

脚本永远不会完成,因为

poller
陷入“InProgress”状态。我该如何调试这个?

python azure email email-attachments azure-communication-services
2个回答
0
投票

我在我的环境中尝试并得到以下结果:

脚本永远不会完成,因为

poller
陷入“InProgress”状态。我该如何调试这个?

poller.result()
永远不会返回,很可能电子邮件发送过程仍在进行中,您可能需要等待操作完成并检查收件人的邮件是否正确。

我使用下面的代码发送带有附件的邮件,并且通过向数据块集群中的收件人发送邮件来成功执行。

代码:

from azure.communication.email import EmailClient
import base64

with open("/dbfs/FileStore/filename.txt", "r") as file:
    file_contents = file.read()

file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))

comm_connection_string="Your connection string"
email_client = EmailClient.from_connection_string(comm_connection_string)
message = {
    "content": {
        "subject": "This is the subject",
        "plainText": "This is the body",
        "html": "<html><h1>This is the body</h1></html>"
    },
        "recipients": {
            "to": [
                {
                    "address": "[email protected]",
                    "displayName": "venkat"
                }
            ]
},
    "senderAddress": "DoNotReply@<Your domain>.azurecomm.net",
    "attachments": [
        {
            "name": "attachment.txt",
            "contentType": "text/plain",
            "contentInBase64": file_bytes_b64.decode()
        }
    ]
}
poller = email_client.begin_send(message)
result = poller.result()

print("Email is send to Recipient Sucessfully")

输出:

enter image description here

邮件:

enter image description here

参考: azure-通信-电子邮件·PyPI


0
投票

您可以在此地址找到解决问题所需的所有信息。

解决Azure通信电子邮件发送操作卡住的问题

© www.soinside.com 2019 - 2024. All rights reserved.