如何从Azure电子邮件服务获取电子邮件消息ID?

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

我正在尝试使用 azure 电子邮件通信 Python SDK 发送电子邮件

poller = self.email_client.begin_send(
                message=payload,
            )

time_elapsed = 0

while not poller.done():
    logger.info("Email send poller status: " + poller.status())

    poller.wait(POLLER_WAIT_TIME)
    time_elapsed += POLLER_WAIT_TIME

    if time_elapsed > 18 * POLLER_WAIT_TIME:
        raise RuntimeError("Polling timed out.")

result = poller.result()

有效负载:

{
    "content": {
        "subject": "Sample Subject",
        "html": "<!DOCTYPE html>\n<html>\n<head>\n\n\n</head>\n<body>\n\n<div style=\"padding-left: 5%; padding-right: 5%\">\n<p>Hello Team,</p></div>\n</body>\n</html>"
    },
    "recipients": {
        "to": [
            {
                "address": "my_email.com",
                "displayName": "My Name"
            }
        ],
        "cc": [],
        "bcc": []
    },
    "senderAddress": "[email protected]",
    "attachments": []
}

结果:

{
   "id":"570e68e8-0418-4cde-bd5e-49d9a9bf3f49",
   "status":"Succeeded",
   "error":null
}

我出于各种目的需要 message_id,但我没有从 azure api 获取 message_id,我是否遗漏了什么?

如何获取发送的邮件的message_id?

azure email imap azure-communication-services
1个回答
0
投票

您可能对此代码感兴趣

from azure.communication.email import EmailClient, EmailContent, 
EmailRecipients, EmailSender
from azure.identity import DefaultAzureCredential

# Initialize the EmailClient with your connection string
email_client = 
EmailClient.from_connection_string("your_connection_string_here")

# Construct the email message payload
email_content = EmailContent(subject="Sample Subject")
email_content.html = "<div><p>Hello Team,</p></div>"
recipients = EmailRecipients(to=[{"email": "[email protected]", 
"displayName": "Recipient Name"}])
sender = EmailSender(email="[email protected]", display_name="Sender 
Name")

# Send the email
send_operation = email_client.send(email_content, recipients, sender)

# Wait for the send operation to complete and retrieve the result
send_result = send_operation.result()

# Extract the Message ID from the send result
message_id = send_result.message_id
print(f"Message ID: {message_id}")

从 Azure 电子邮件服务检索消息 ID

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