如何从Mailgun API域队列中删除邮件?

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

我正在 PHP Laminas 中编写一个模块,通过 Mailgun API 发送邮件。我能够发送邮件并列出待处理队列。我想使用

message-id
删除 mailgun 中的特定邮件。如果可能的话,有人可以指导我吗?如果是的话,怎么办?

我在文档方面得到的最接近的是清除域队列,这不是我想要的。 https://help.mailgun.com/hc/en-us/articles/360012487654-如何从队列中删除消息-

下面是我编写的使用 Mailgun 发送邮件的代码。

    /**
     * MailgunApiSendRequest constructor.
     *
     * @param MailgunApiModel $mailgunApiModel
     * @param MailgunApiSendResponse $mailgunApiSendResponse
     */
    public function __construct(MailgunApiModel $mailgunApiModel, MailgunApiSendResponse $mailgunApiSendResponse)
    {
        $this->mailgunApiModel = $mailgunApiModel;
        $this->mailgunApiSendResponse = $mailgunApiSendResponse;
    }

    /**
     * @return MailgunApiSendResponse
     * @throws ClientExceptionInterface
     */
    public function send(): MailgunApiSendResponse
    {
        /** @var Mailgun $mailgun */
        $mailgun = $this->getMailgunApiClient()->create();

        /** @var array[] $params */
        $params = [
            "from" => $this->getMailgunApiClient()->getFromEmail(),
            "to" => $this->getMailgunApiModel()->getEmailAddress(),
            "subject" => $this->getMailgunApiModel()->getTitle(),
            "text" => $this->getMailgunApiModel()->getContent(),
            "o:deliverytime" => Carbon::now()->adddays(3)->toRfc2822String(),
        ];

        /** @var SendResponse $sendResponse */
        $sendResponse = $mailgun->messages()->send($this->getMailgunApiClient()->getEmailDomain(), $params);

        /** @var array[] $data */
        $data = [
            "id" => $sendResponse->getId(),
            "message" => $sendResponse->getMessage()
        ];

        $this->getMailgunApiSendResponse()->setResponse($data);

        return $this->getMailgunApiSendResponse();
    }

以下是 Mailgun 日志中的当前状态。

{
    "envelope": {
        "transport": "smtp",
        "sender": "[email protected]",
        "targets": "gohar*****@gmail.com"
    },
    "storage": {
        "region": "us-west1",
        "env": "production",
        "key": "BAABAQYhT_85YerJ675CSDFASXxRjabYg==",
        "url": "https://storage-us-west1.api.mailgun.net/v3/domains/sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org/messages/BAABAQYhT_85YerJ675CbouSEEXxRjabYg=="
    },
    "method": "HTTP",
    "log-level": "info",
    "recipient-domain": "gmail.com",
    "event": "accepted",
    "user-variables": {},
    "id": "984HKEiQRemVjMeFKoHyyw",
    "recipient": "gohar*****@gmail.com",
    "tags": null,
    "timestamp": 1684929274.7635095,
    "flags": {
        "is-test-mode": false,
        "is-authenticated": true
    },
    "message": {
        "size": 387,
        "headers": {
            "from": "Admin <[email protected]>",
            "subject": "Live Test",
            "message-id": "20230524115434.bc162edb03872131@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org",
            "to": "gohar*****@gmail.com"
        },
        "scheduled-for": 1685188473
    },
    "originating-ip": "124.29.239.111"
}

"scheduled-for": 1685188473
显示3天后发送。

php mailgun
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.