Closed fasc8 closed 1 month ago
Further research into why no email is sent has let me down to look into the whole user creation (addition) process.
After looking into what prerequisites the ProcessMailingCommand
and subsequently the MailingService
need, I had a look into the database and realized that there is no entry in the mailing
table after a new user is created. As this is required to have an email sent via the ProcessMailingCommand
, I continued to look into where this entry should have come from in the first place.
I currently assume that the following method in the UserSubscriber
is not called / firing:
#[NoReturn]
public function onUserCreated(UserCreatedEvent $event)
{
$user = $event->getUser();
$isAdmin = in_array(Role::ADMINISTRATOR->string(), $user->getRoles(), true);
if (!$isAdmin) {
$isAlone = count($this->userRepository->findAllExcept($user)) === 0;
if ($isAlone) {
$user->setRoles(User::getAllNonAdminRoles());
$hasNoGroups = count($this->groupRepository->findAll()) === 0;
if ($hasNoGroups) {
$newGroup = $this->groupService->createGroup("Team", null);
$this->userService->addUserToGroups($user, [$newGroup]);
}
}
$userIsMissingUserRole = !in_array(Role::USER->string(), $user->getRoles(), true);
if ($userIsMissingUserRole) {
$newRoles = $user->getRoles();
$newRoles[] = Role::USER->string();
$user->setRoles($newRoles);
}
if ($user->getDateFormat() === null || $user->getDateFormat() === '') {
$user->setDateFormat(DateTimeUtil::DEFAULT_DATE_FORMAT);
}
}
$mailTemplate = $event->getMailTemplate();
$this->userService->welcomeUser($user, $mailTemplate); # <---------------
$this->entityManager->flush();
}
Which leads to never calling the welcomeUser
method which would perform a password reset on the newly created user and insert a mailing into the mailing
table. Which in turn would then get picked up by the ProcessMailingCommand
and sends the mail.
I am not sure how to test for this which is why it is only my assumption at the moment. Hopefully this can help you in finding a solution to my problem.
Looking into the Symfony event dispatcher shows that the UserCreatedEvent
is needed to get the aforementioned onUserCreated
method to be called. Searching through the source files it seems that this event is never called.
Hi fasc8, Indeed, UserCreatedEvent was not created after register. Should be fixed now. Regards.
I cannot get the email sending to work which is required to create new users and I assume is useful beyond that.
My situation: I have an SMTP server running which I can connect to from my container (I checked for that by manually sending a mail via curl request:
curl --url 'smtp://localhost:25' --mail-rcpt 'recipient@example.com' -T <(echo -e 'From: from-email@gmail.com\nTo: to-email@gmail.com\nSubject: Curl Test\n\nHello')
). The server uses an anonymous login, so no username and password is required. To make sammy compatible with that I did the following changes to the MailingService and the ProcessMailingCommand:I also added the appropriate environment variables to the compose file with the host and port. As the username and password are not used anymore, I did not added them to the compose file.
My hope was that this would achieve disabling authentication for sending emails while leaving all other functionality intact. But now I encounter the issue that no emails are sent.
Further debugging showed that the
processMailing()
function never goes into its for loops and just runs through. Even though I created new users and therefore an email should have been sent to them to provide them with login credentials.I hope you can help me to find a solution. Looking forward to your replies.