99use Dot \DependencyInjection \Attribute \Inject ;
1010use Dot \Log \LoggerInterface ;
1111use Dot \Mail \Exception \MailException ;
12- use Mezzio \Template \TemplateRendererInterface ;
1312use Symfony \Component \Mailer \Exception \TransportExceptionInterface ;
1413
1514use function sprintf ;
1615
1716class MailService
1817{
1918 #[Inject(
20- TemplateRendererInterface::class,
2119 'dot-mail.service.default ' ,
2220 'dot-log.default_logger ' ,
2321 'config ' ,
2422 )]
2523 public function __construct (
26- private readonly TemplateRendererInterface $ templateRenderer ,
2724 protected \Dot \Mail \Service \MailService $ mailService ,
2825 protected LoggerInterface $ logger ,
2926 private readonly array $ config ,
@@ -33,20 +30,15 @@ public function __construct(
3330 /**
3431 * @throws MailException
3532 */
36- public function sendActivationMail (User $ user ): bool
33+ public function sendActivationMail (User $ user, string $ body ): bool
3734 {
3835 if ($ user ->isActive ()) {
3936 return false ;
4037 }
4138
4239 $ this ->mailService ->getMessage ()->addTo ($ user ->getDetail ()->getEmail (), $ user ->getName ());
4340 $ this ->mailService ->setSubject ('Welcome to ' . $ this ->config ['application ' ]['name ' ]);
44- $ this ->mailService ->setBody (
45- $ this ->templateRenderer ->render ('user::activate ' , [
46- 'config ' => $ this ->config ,
47- 'user ' => $ user ,
48- ])
49- );
41+ $ this ->mailService ->setBody ($ body );
5042
5143 try {
5244 return $ this ->mailService ->send ()->isValid ();
@@ -59,18 +51,13 @@ public function sendActivationMail(User $user): bool
5951 /**
6052 * @throws MailException
6153 */
62- public function sendResetPasswordRequestedMail (User $ user ): bool
54+ public function sendResetPasswordRequestedMail (User $ user, string $ body ): bool
6355 {
6456 $ this ->mailService ->getMessage ()->addTo ($ user ->getDetail ()->getEmail (), $ user ->getName ());
6557 $ this ->mailService ->setSubject (
6658 'Reset password instructions for your ' . $ this ->config ['application ' ]['name ' ] . ' account '
6759 );
68- $ this ->mailService ->setBody (
69- $ this ->templateRenderer ->render ('user::reset-password-requested ' , [
70- 'config ' => $ this ->config ,
71- 'user ' => $ user ,
72- ])
73- );
60+ $ this ->mailService ->setBody ($ body );
7461
7562 try {
7663 return $ this ->mailService ->send ()->isValid ();
@@ -83,18 +70,13 @@ public function sendResetPasswordRequestedMail(User $user): bool
8370 /**
8471 * @throws MailException
8572 */
86- public function sendResetPasswordCompletedMail (User $ user ): bool
73+ public function sendResetPasswordCompletedMail (User $ user, string $ body ): bool
8774 {
8875 $ this ->mailService ->getMessage ()->addTo ($ user ->getDetail ()->getEmail (), $ user ->getName ());
8976 $ this ->mailService ->setSubject (
9077 'You have successfully reset the password for your ' . $ this ->config ['application ' ]['name ' ] . ' account '
9178 );
92- $ this ->mailService ->setBody (
93- $ this ->templateRenderer ->render ('user::reset-password-completed ' , [
94- 'config ' => $ this ->config ,
95- 'user ' => $ user ,
96- ])
97- );
79+ $ this ->mailService ->setBody ($ body );
9880
9981 try {
10082 return $ this ->mailService ->send ()->isValid ();
@@ -107,16 +89,13 @@ public function sendResetPasswordCompletedMail(User $user): bool
10789 /**
10890 * @throws MailException
10991 */
110- public function sendWelcomeMail (User $ user ): bool
92+ public function sendRecoverIdentityMail (User $ user, string $ body ): bool
11193 {
11294 $ this ->mailService ->getMessage ()->addTo ($ user ->getDetail ()->getEmail (), $ user ->getName ());
113- $ this ->mailService ->setSubject ('Welcome to ' . $ this ->config ['application ' ]['name ' ]);
114- $ this ->mailService ->setBody (
115- $ this ->templateRenderer ->render ('user::welcome ' , [
116- 'config ' => $ this ->config ,
117- 'user ' => $ user ,
118- ])
95+ $ this ->mailService ->setSubject (
96+ 'Recover identity for your ' . $ this ->config ['application ' ]['name ' ] . ' account '
11997 );
98+ $ this ->mailService ->setBody ($ body );
12099
121100 try {
122101 return $ this ->mailService ->send ()->isValid ();
@@ -129,18 +108,11 @@ public function sendWelcomeMail(User $user): bool
129108 /**
130109 * @throws MailException
131110 */
132- public function sendRecoverIdentityMail (User $ user ): bool
111+ public function sendWelcomeMail (User $ user, string $ body ): bool
133112 {
134113 $ this ->mailService ->getMessage ()->addTo ($ user ->getDetail ()->getEmail (), $ user ->getName ());
135- $ this ->mailService ->setSubject (
136- 'Recover identity for your ' . $ this ->config ['application ' ]['name ' ] . ' account '
137- );
138- $ this ->mailService ->setBody (
139- $ this ->templateRenderer ->render ('user::recover-identity-requested ' , [
140- 'config ' => $ this ->config ,
141- 'user ' => $ user ,
142- ])
143- );
114+ $ this ->mailService ->setSubject ('Welcome to ' . $ this ->config ['application ' ]['name ' ]);
115+ $ this ->mailService ->setBody ($ body );
144116
145117 try {
146118 return $ this ->mailService ->send ()->isValid ();
0 commit comments