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

yftpprvb  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(114)

我正在使用azure-communication-email python包从Databricks集群发送电子邮件。该脚本在旧版本中运行良好,但他们最近推出了新版本(版本1.0.0b2从03/07/23),该版本使用了不同的排版风格。

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": "DoNotReply@azurecomm.net",
    "attachments": [
        {
            "name":save_name,
            "contentType": "txt",
            "contentInBase64": file_bytes_b64.decode()
        }
    ]
}
poller = email_client.begin_send(message)
result = poller.result()

由于poller停留在“InProgress”状态,脚本永远无法完成。我如何调试这个问题?

x3naxklr

x3naxklr1#

我在自己的环境中尝试,得到了以下结果:

由于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": "youremail@gmail.com",
                    "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")

输出:

邮箱:

参考:azure-communication-email · PyPI

相关问题