Inbound.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. class Mandrill_Inbound {
  3. public function __construct(Mandrill $master) {
  4. $this->master = $master;
  5. }
  6. /**
  7. * List the domains that have been configured for inbound delivery
  8. * @return array the inbound domains associated with the account
  9. * - return[] struct the individual domain info
  10. * - domain string the domain name that is accepting mail
  11. * - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
  12. * - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
  13. */
  14. public function domains() {
  15. $_params = array();
  16. return $this->master->call('inbound/domains', $_params);
  17. }
  18. /**
  19. * Add an inbound domain to your account
  20. * @param string $domain a domain name
  21. * @return struct information about the domain
  22. * - domain string the domain name that is accepting mail
  23. * - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
  24. * - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
  25. */
  26. public function addDomain($domain) {
  27. $_params = array("domain" => $domain);
  28. return $this->master->call('inbound/add-domain', $_params);
  29. }
  30. /**
  31. * Check the MX settings for an inbound domain. The domain must have already been added with the add-domain call
  32. * @param string $domain an existing inbound domain
  33. * @return struct information about the inbound domain
  34. * - domain string the domain name that is accepting mail
  35. * - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
  36. * - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
  37. */
  38. public function checkDomain($domain) {
  39. $_params = array("domain" => $domain);
  40. return $this->master->call('inbound/check-domain', $_params);
  41. }
  42. /**
  43. * Delete an inbound domain from the account. All mail will stop routing for this domain immediately.
  44. * @param string $domain an existing inbound domain
  45. * @return struct information about the deleted domain
  46. * - domain string the domain name that is accepting mail
  47. * - created_at string the date and time that the inbound domain was added as a UTC string in YYYY-MM-DD HH:MM:SS format
  48. * - valid_mx boolean true if this inbound domain has successfully set up an MX record to deliver mail to the Mandrill servers
  49. */
  50. public function deleteDomain($domain) {
  51. $_params = array("domain" => $domain);
  52. return $this->master->call('inbound/delete-domain', $_params);
  53. }
  54. /**
  55. * List the mailbox routes defined for an inbound domain
  56. * @param string $domain the domain to check
  57. * @return array the routes associated with the domain
  58. * - return[] struct the individual mailbox route
  59. * - id string the unique identifier of the route
  60. * - pattern string the search pattern that the mailbox name should match
  61. * - url string the webhook URL where inbound messages will be published
  62. */
  63. public function routes($domain) {
  64. $_params = array("domain" => $domain);
  65. return $this->master->call('inbound/routes', $_params);
  66. }
  67. /**
  68. * Add a new mailbox route to an inbound domain
  69. * @param string $domain an existing inbound domain
  70. * @param string $pattern the search pattern that the mailbox name should match
  71. * @param string $url the webhook URL where the inbound messages will be published
  72. * @return struct the added mailbox route information
  73. * - id string the unique identifier of the route
  74. * - pattern string the search pattern that the mailbox name should match
  75. * - url string the webhook URL where inbound messages will be published
  76. */
  77. public function addRoute($domain, $pattern, $url) {
  78. $_params = array("domain" => $domain, "pattern" => $pattern, "url" => $url);
  79. return $this->master->call('inbound/add-route', $_params);
  80. }
  81. /**
  82. * Update the pattern or webhook of an existing inbound mailbox route. If null is provided for any fields, the values will remain unchanged.
  83. * @param string $id the unique identifier of an existing mailbox route
  84. * @param string $pattern the search pattern that the mailbox name should match
  85. * @param string $url the webhook URL where the inbound messages will be published
  86. * @return struct the updated mailbox route information
  87. * - id string the unique identifier of the route
  88. * - pattern string the search pattern that the mailbox name should match
  89. * - url string the webhook URL where inbound messages will be published
  90. */
  91. public function updateRoute($id, $pattern=null, $url=null) {
  92. $_params = array("id" => $id, "pattern" => $pattern, "url" => $url);
  93. return $this->master->call('inbound/update-route', $_params);
  94. }
  95. /**
  96. * Delete an existing inbound mailbox route
  97. * @param string $id the unique identifier of an existing route
  98. * @return struct the deleted mailbox route information
  99. * - id string the unique identifier of the route
  100. * - pattern string the search pattern that the mailbox name should match
  101. * - url string the webhook URL where inbound messages will be published
  102. */
  103. public function deleteRoute($id) {
  104. $_params = array("id" => $id);
  105. return $this->master->call('inbound/delete-route', $_params);
  106. }
  107. /**
  108. * Take a raw MIME document destined for a domain with inbound domains set up, and send it to the inbound hook exactly as if it had been sent over SMTP
  109. * @param string $raw_message the full MIME document of an email message
  110. * @param array|null $to optionally define the recipients to receive the message - otherwise we'll use the To, Cc, and Bcc headers provided in the document
  111. * - to[] string the email address of the recipient
  112. * @param string $mail_from the address specified in the MAIL FROM stage of the SMTP conversation. Required for the SPF check.
  113. * @param string $helo the identification provided by the client mta in the MTA state of the SMTP conversation. Required for the SPF check.
  114. * @param string $client_address the remote MTA's ip address. Optional; required for the SPF check.
  115. * @return array an array of the information for each recipient in the message (usually one) that matched an inbound route
  116. * - return[] struct the individual recipient information
  117. * - email string the email address of the matching recipient
  118. * - pattern string the mailbox route pattern that the recipient matched
  119. * - url string the webhook URL that the message was posted to
  120. */
  121. public function sendRaw($raw_message, $to=null, $mail_from=null, $helo=null, $client_address=null) {
  122. $_params = array("raw_message" => $raw_message, "to" => $to, "mail_from" => $mail_from, "helo" => $helo, "client_address" => $client_address);
  123. return $this->master->call('inbound/send-raw', $_params);
  124. }
  125. }