You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/book/v6/extended-features/email.md
+66-4Lines changed: 66 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,73 @@
1
1
# Email sending and content parsing
2
2
3
3
In the previous version of Dotkernel API we have been using the `mezzio/mezzio-twigrenderer` package which added unnecessary complexity to the email sending in our API platform since APIs returns JSON data, not HTML.
4
-
In order to fix this issue, we have come up with a lighter custom solution.
4
+
Besides this, it used two services (`AdminService` and `UserService`) to send emails.
5
+
It was not necessarily wrong, but their job should be only to manage Admin/User accounts.
6
+
7
+
In order to fix this those problems, we have come up with a lighter custom solution.
5
8
Now each project can prepare the bodies of the emails by using its preferred template renderer.
6
-
`Core\App\MailService` is now decoupled by injecting the pre-rendered email body when calling its methods.
9
+
`Core/src/App/src/Service/MailService` is now decoupled by injecting the pre-rendered email body when calling its methods.
10
+
11
+
Example from `Core/src/App/src/Service/MailService.php`:
12
+
13
+
```php
14
+
<?php
15
+
16
+
declare(strict_types=1);
17
+
18
+
namespace Core\App\Service;
19
+
20
+
use Core\App\Message;
21
+
use Core\User\Entity\User;
22
+
use Dot\DependencyInjection\Attribute\Inject;
23
+
use Dot\Log\LoggerInterface;
24
+
use Dot\Mail\Exception\MailException;
25
+
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
throw new MailException(sprintf(Message::MAIL_NOT_SENT_TO, $user->getEmail()));
64
+
}
65
+
}
66
+
}
67
+
```
68
+
69
+
Rending example from `src/User/src/Handler/PostUserResourceHandler.php`:
7
70
8
-
Example from `src/User/src/Handler/PostUserResourceHandler.php`:
9
71
```php
10
72
if ($user->isPending()) {
11
73
$this->mailService->sendActivationMail(
@@ -14,8 +76,8 @@ if ($user->isPending()) {
14
76
);
15
77
}
16
78
```
79
+
17
80
In this case we are using the `phtml` template from `src/User/src/templates`.
18
81
It has a lighter format compared to `twig`.
19
82
It is then rendered before sending the activation email by our custom renderer from `src/App/src/Template/Rederer.php`.
20
83
The other applications that use the Core structure such as [Dotkernel Admin](https://docs.dotkernel.org/admin-documentation/) use `mezzio/mezzio-twigrenderer` for this purpose.
0 commit comments