我正在使用
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”状态。我该如何调试这个?
我在我的环境中尝试并得到以下结果:
脚本永远不会完成,因为
陷入“InProgress”状态。我该如何调试这个?poller
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")
输出:
邮件:
您可以在此地址找到解决问题所需的所有信息。