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

huangapple go评论81阅读模式
英文:

How to delete a mail from Mailgun API domain queue?

问题

我正在使用PHP Laminas编写一个模块,用于通过Mailgun API发送邮件。我能够成功发送邮件并列出待处理队列。我想通过message-id删除Mailgun中的特定邮件。请问是否可能?如果可以,应该如何操作?

根据我找到的文档,最接近的方法是清空域队列,但这并不是我想要的操作。
https://help.mailgun.com/hc/en-us/articles/360012487654-How-Can-I-Delete-Messages-From-the-Queue-

以下是我用于使用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": "Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org",
		"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 <Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org>",
			"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天后发送。

英文:

I'm writing a module in PHP Laminas to send mails through Mailgun API. I'm able to send the mail as well as list the pending queue. I want to delete a particular mail in mailgun using message-id. Can someone please guide me if its even possible? If yes, how?

The closest I've got in terms of documentation is clearing the domain queue which isn't what I want.
https://help.mailgun.com/hc/en-us/articles/360012487654-How-Can-I-Delete-Messages-From-the-Queue-

Below is the code I've written to send the mail using Mailgun.

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

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

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

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

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

        $this-&gt;getMailgunApiSendResponse()-&gt;setResponse($data);

        return $this-&gt;getMailgunApiSendResponse();
    }

Below is the current status as per Mailgun Log.

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

&quot;scheduled-for&quot;: 1685188473 shows that its going to be sent after 3 days.

答案1

得分: 0

Mailgun不提供删除邮件的选项。

链接:https://documentation.mailgun.com/en/latest/api-sending.html#retrieving-stored-messages:~:text=process%20this%20data.-,Deleting%20Stored%20Messages,-Stored%20messages%20are

英文:

Mailgun doesn't provide the option to delete mails.

https://documentation.mailgun.com/en/latest/api-sending.html#retrieving-stored-messages:~:text=process%20this%20data.-,Deleting%20Stored%20Messages,-Stored%20messages%20are

huangapple
  • 本文由 发表于 2023年5月24日 20:11:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定