1
0

IMailer.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCP\Mail;
  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' => 'Nextcloud 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 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. }