在 Outlook 中创建草稿电子邮件

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

如何创建电子邮件草稿? 我一直在尝试找出如何在 Outlook 中使用 php 将电子邮件保存为草稿。 通过执行脚本,草稿电子邮件会在 Outlook 草稿部分生成,如果需要,我可以随时发送电子邮件。

php email outlook phpmailer html-email
2个回答
1
投票

这种问题对于SO来说太开放了,但这里是你可以做什么的顶层视图。

您可以使用 PHP 创建消息并通过 Outlook 的 API 或 IMAP 将其上传到草稿文件夹(PHPMailer gmail 示例中有一个针对已发送消息执行此操作的示例)。

相反,您可以在 Outlook 中创建并保存草稿,然后通过 API 或 IMAP 访问它,将其拉入 PHP 脚本,您可以在其中执行您喜欢的操作,包括发送或上传到其他帐户。


0
投票

请参阅:Graph API 文档

您可以通过他们的 PHP SDK 使用:

composer require microsoft/microsoft-graph

您基本上只需要确保

isDraft
设置为 true,然后该消息就会进入您的草稿文件夹。

$token = 'your API token';
$user = 'the userid of the account you want to put the draft into';

$body = [
    'isDraft' => true,
    'toRecipients' => 'the recipient(s)',
    'subject' => 'the subject',
    'body' => [
       'content' => 'the HTML body',
       'contentType' => 'HTML',
    ],
];

(new \Microsoft\Graph\Graph())
    ->setAccessToken($token)
    ->createRequest('POST', "/users/$user/messages")
    ->attachBody($body)
    ->execute();
© www.soinside.com 2019 - 2024. All rights reserved.