1
0

IMailer.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP\Mail;
  25. use OC\Mail\Message;
  26. /**
  27. * Class IMailer provides some basic functions to create a mail message that can be used in combination with
  28. * \OC\Mail\Message.
  29. *
  30. * Example usage:
  31. *
  32. * $mailer = \OC::$server->getMailer();
  33. * $message = $mailer->createMessage();
  34. * $message->setSubject('Your Subject');
  35. * $message->setFrom(['cloud@domain.org' => 'ownCloud Notifier']);
  36. * $message->setTo(['recipient@domain.org' => 'Recipient']);
  37. * $message->setPlainBody('The message text');
  38. * $message->setHtmlBody('The <strong>message</strong> text');
  39. * $mailer->send($message);
  40. *
  41. * This message can then be passed to send() of \OC\Mail\Mailer
  42. *
  43. * @package OCP\Mail
  44. * @since 8.1.0
  45. */
  46. interface IMailer {
  47. /**
  48. * Creates a new message object that can be passed to send()
  49. *
  50. * @return Message
  51. * @since 8.1.0
  52. */
  53. public function createMessage();
  54. /**
  55. * Send the specified message. Also sets the from address to the value defined in config.php
  56. * if no-one has been passed.
  57. *
  58. * @param Message $message Message to send
  59. * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
  60. * therefore should be considered
  61. * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
  62. * has been supplied.)
  63. * @since 8.1.0
  64. */
  65. public function send(Message $message);
  66. /**
  67. * Checks if an e-mail address is valid
  68. *
  69. * @param string $email Email address to be validated
  70. * @return bool True if the mail address is valid, false otherwise
  71. * @since 8.1.0
  72. */
  73. public function validateMailAddress($email);
  74. }