我正在尝试构建一个应用程序来处理和重新发送来自用户邮件收件箱的消息。
我尝试遵循示例代码(如下)。然而,示例代码中引用的 .py 文件之一似乎丢失了。因为我需要包含附件,所以使用 requests 库来做同样的工作会很不舒服。
示例代码:
from msgraph import GraphServiceClient
from msgraph.generated.models.send_mail_post_request_body import SendMailPostRequestBody
from msgraph.generated.models.message import Message
from msgraph.generated.models.item_body import ItemBody
from msgraph.generated.models.recipient import Recipient
from msgraph.generated.models.email_address import EmailAddress
graph_client = GraphServiceClient(credentials, scopes)
request_body = SendMailPostRequestBody(
message = Message(
subject = "Meet for lunch?",
body = ItemBody(
content_type = BodyType.Text,
content = "The new cafeteria is open.",
),
to_recipients = [
Recipient(
email_address = EmailAddress(
address = "[email protected]",
),
),
],
cc_recipients = [
Recipient(
email_address = EmailAddress(
address = "[email protected]",
),
),
],
),
save_to_sent_items = False,
)
await graph_client.me.send_mail.post(request_body)
msgraph 模块中没有 SendMailPostRequestBody 类。
您的进口声明应该是
from msgraph.generated.users.item.send_mail.send_mail_post_request_body import SendMailPostRequestBody
您可以查看https://github.com/microsoftgraph/msgraph-sdk-python/issues/391,其中讨论了此问题,并且还包含一些应该有效的示例代码。