From 022b1bf92346b87fd187761435f755ddb2c770e7 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 1 Jun 2023 18:01:42 +0200 Subject: [PATCH] feat(devmanual): Document IMailer and inline attachments Signed-off-by: Christoph Wurst --- developer_manual/digging_deeper/email.rst | 46 +++++++++++++++++++++++ developer_manual/digging_deeper/index.rst | 1 + 2 files changed, 47 insertions(+) create mode 100644 developer_manual/digging_deeper/email.rst diff --git a/developer_manual/digging_deeper/email.rst b/developer_manual/digging_deeper/email.rst new file mode 100644 index 000000000..11856272f --- /dev/null +++ b/developer_manual/digging_deeper/email.rst @@ -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`: + +.. code-block:: php + :caption: lib/Service/MailService.php + + 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); diff --git a/developer_manual/digging_deeper/index.rst b/developer_manual/digging_deeper/index.rst index b9e415ebd..368ea6525 100644 --- a/developer_manual/digging_deeper/index.rst +++ b/developer_manual/digging_deeper/index.rst @@ -10,6 +10,7 @@ Digging deeper debugging classloader continuous_integration + email flow http_client javascript-apis