feat(devmanual): Document IMailer and inline attachments

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst
2023-06-01 18:01:42 +02:00
parent dda5c9bab0
commit 022b1bf923
2 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
=====
Email
=====
Nextcloud has a mailer component to send email from an admin-defined account.
Basic usage
-----------
The mailer is hidden behind the ``\OCP\Mail\IMailer`` interface that can be :ref:`injected<dependency-injection>`:
.. code-block:: php
:caption: lib/Service/MailService.php
<?php
use OCP\Mail\IMailer;
class MailService {
private IMailer $mailer;
public function __construct(IMailer $mailer) {
$this->mailer = $mailer;
}
public function notify(string $email): void {
$message = $this->mailer->createMessage();
$message->setTo([$email]);
$this->mailer->send($message);
}
}
Inline attachments
------------------
Inline attachments can be appended to a message with ``IMessage::attachInline``:
.. code-block:: php
/** @var IMessage $message */
$message->attachInline(
"this is a test", // Body
"test.txt", // Name
"text/plain" // Content type
);
$this->mailer->send($message);

View File

@@ -10,6 +10,7 @@ Digging deeper
debugging
classloader
continuous_integration
email
flow
http_client
javascript-apis