You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

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