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

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

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发送邮件的代码。

  1. /**
  2. * MailgunApiSendRequest constructor.
  3. *
  4. * @param MailgunApiModel $mailgunApiModel
  5. * @param MailgunApiSendResponse $mailgunApiSendResponse
  6. */
  7. public function __construct(MailgunApiModel $mailgunApiModel, MailgunApiSendResponse $mailgunApiSendResponse)
  8. {
  9. $this->mailgunApiModel = $mailgunApiModel;
  10. $this->mailgunApiSendResponse = $mailgunApiSendResponse;
  11. }
  12. /**
  13. * @return MailgunApiSendResponse
  14. * @throws ClientExceptionInterface
  15. */
  16. public function send(): MailgunApiSendResponse
  17. {
  18. /** @var Mailgun $mailgun */
  19. $mailgun = $this->getMailgunApiClient()->create();
  20. /** @var array[] $params */
  21. $params = [
  22. "from" => $this->getMailgunApiClient()->getFromEmail(),
  23. "to" => $this->getMailgunApiModel()->getEmailAddress(),
  24. "subject" => $this->getMailgunApiModel()->getTitle(),
  25. "text" => $this->getMailgunApiModel()->getContent(),
  26. "o:deliverytime" => Carbon::now()->addDays(3)->toRfc2822String(),
  27. ];
  28. /** @var SendResponse $sendResponse */
  29. $sendResponse = $mailgun->messages()->send($this->getMailgunApiClient()->getEmailDomain(), $params);
  30. /** @var array[] $data */
  31. $data = [
  32. "id" => $sendResponse->getId(),
  33. "message" => $sendResponse->getMessage()
  34. ];
  35. $this->getMailgunApiSendResponse()->setResponse($data);
  36. return $this->getMailgunApiSendResponse();
  37. }

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

  1. {
  2. "envelope": {
  3. "transport": "smtp",
  4. "sender": "Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org",
  5. "targets": "gohar*****@gmail.com"
  6. },
  7. "storage": {
  8. "region": "us-west1",
  9. "env": "production",
  10. "key": "BAABAQYhT_85YerJ675CSDFASXxRjabYg==",
  11. "url": "https://storage-us-west1.api.mailgun.net/v3/domains/sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org/messages/BAABAQYhT_85YerJ675CbouSEEXxRjabYg=="
  12. },
  13. "method": "HTTP",
  14. "log-level": "info",
  15. "recipient-domain": "gmail.com",
  16. "event": "accepted",
  17. "user-variables": {},
  18. "id": "984HKEiQRemVjMeFKoHyyw",
  19. "recipient": "gohar*****@gmail.com",
  20. "tags": null,
  21. "timestamp": 1684929274.7635095,
  22. "flags": {
  23. "is-test-mode": false,
  24. "is-authenticated": true
  25. },
  26. "message": {
  27. "size": 387,
  28. "headers": {
  29. "from": "Admin <Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org>",
  30. "subject": "Live Test",
  31. "message-id": "20230524115434.bc162edb03872131@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org",
  32. "to": "gohar*****@gmail.com"
  33. },
  34. "scheduled-for": 1685188473
  35. },
  36. "originating-ip": "124.29.239.111"
  37. }

"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.

  1. /**
  2. * MailgunApiSendRequest constructor.
  3. *
  4. * @param MailgunApiModel $mailgunApiModel
  5. * @param MailgunApiSendResponse $mailgunApiSendResponse
  6. */
  7. public function __construct(MailgunApiModel $mailgunApiModel, MailgunApiSendResponse $mailgunApiSendResponse)
  8. {
  9. $this-&gt;mailgunApiModel = $mailgunApiModel;
  10. $this-&gt;mailgunApiSendResponse = $mailgunApiSendResponse;
  11. }
  12. /**
  13. * @return MailgunApiSendResponse
  14. * @throws ClientExceptionInterface
  15. */
  16. public function send(): MailgunApiSendResponse
  17. {
  18. /** @var Mailgun $mailgun */
  19. $mailgun = $this-&gt;getMailgunApiClient()-&gt;create();
  20. /** @var array[] $params */
  21. $params = [
  22. &quot;from&quot; =&gt; $this-&gt;getMailgunApiClient()-&gt;getFromEmail(),
  23. &quot;to&quot; =&gt; $this-&gt;getMailgunApiModel()-&gt;getEmailAddress(),
  24. &quot;subject&quot; =&gt; $this-&gt;getMailgunApiModel()-&gt;getTitle(),
  25. &quot;text&quot; =&gt; $this-&gt;getMailgunApiModel()-&gt;getContent(),
  26. &quot;o:deliverytime&quot; =&gt; Carbon::now()-&gt;adddays(3)-&gt;toRfc2822String(),
  27. ];
  28. /** @var SendResponse $sendResponse */
  29. $sendResponse = $mailgun-&gt;messages()-&gt;send($this-&gt;getMailgunApiClient()-&gt;getEmailDomain(), $params);
  30. /** @var array[] $data */
  31. $data = [
  32. &quot;id&quot; =&gt; $sendResponse-&gt;getId(),
  33. &quot;message&quot; =&gt; $sendResponse-&gt;getMessage()
  34. ];
  35. $this-&gt;getMailgunApiSendResponse()-&gt;setResponse($data);
  36. return $this-&gt;getMailgunApiSendResponse();
  37. }

Below is the current status as per Mailgun Log.

  1. {
  2. &quot;envelope&quot;: {
  3. &quot;transport&quot;: &quot;smtp&quot;,
  4. &quot;sender&quot;: &quot;Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org&quot;,
  5. &quot;targets&quot;: &quot;gohar*****@gmail.com&quot;
  6. },
  7. &quot;storage&quot;: {
  8. &quot;region&quot;: &quot;us-west1&quot;,
  9. &quot;env&quot;: &quot;production&quot;,
  10. &quot;key&quot;: &quot;BAABAQYhT_85YerJ675CSDFASXxRjabYg==&quot;,
  11. &quot;url&quot;: &quot;https://storage-us-west1.api.mailgun.net/v3/domains/sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org/messages/BAABAQYhT_85YerJ675CbouSEEXxRjabYg==&quot;
  12. },
  13. &quot;method&quot;: &quot;HTTP&quot;,
  14. &quot;log-level&quot;: &quot;info&quot;,
  15. &quot;recipient-domain&quot;: &quot;gmail.com&quot;,
  16. &quot;event&quot;: &quot;accepted&quot;,
  17. &quot;user-variables&quot;: {},
  18. &quot;id&quot;: &quot;984HKEiQRemVjMeFKoHyyw&quot;,
  19. &quot;recipient&quot;: &quot;gohar*****@gmail.com&quot;,
  20. &quot;tags&quot;: null,
  21. &quot;timestamp&quot;: 1684929274.7635095,
  22. &quot;flags&quot;: {
  23. &quot;is-test-mode&quot;: false,
  24. &quot;is-authenticated&quot;: true
  25. },
  26. &quot;message&quot;: {
  27. &quot;size&quot;: 387,
  28. &quot;headers&quot;: {
  29. &quot;from&quot;: &quot;Admin &lt;Admin@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org&gt;&quot;,
  30. &quot;subject&quot;: &quot;Live Test&quot;,
  31. &quot;message-id&quot;: &quot;20230524115434.bc162edb03872131@sandboxf130aeded8d44db4b211ec6bb2488f14.mailgun.org&quot;,
  32. &quot;to&quot;: &quot;gohar*****@gmail.com&quot;
  33. },
  34. &quot;scheduled-for&quot;: 1685188473
  35. },
  36. &quot;originating-ip&quot;: &quot;124.29.239.111&quot;
  37. }

&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:

确定