-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(sharebymail): Use initiator's email as sender if mail providers enabled #57080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…enabled Signed-off-by: Abhinav Ohri <[email protected]>
tcitworld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not how it works.
Checkout https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/groupware/mail_provider.html and #45383
|
Hi @tcitworld, I have implemented the same functionality using mail manager api. Could you please confirm if this is what you asked for? |
lib/public/Util.php
Outdated
| * | ||
| * If mail providers are enabled, uses the specified user's email address. | ||
| * If disabled or the user has no valid email, falls back to the system default. | ||
| * @since 31.0.12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @since 31.0.12 | |
| * @since 33.0.0 |
lib/public/Util.php
Outdated
| * If disabled or the user has no valid email, falls back to the system default. | ||
| * @since 31.0.12 | ||
| */ | ||
| public static function getEmailAddressForUser(?IUser $user, string $fallback_user_part): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check $user !== null should be done outside for a cleaner api.
lib/public/Util.php
Outdated
| return self::getDefaultEmailAddress($fallback_user_part); | ||
| } | ||
|
|
||
| $config = \OCP\Server::get(serviceName: IConfig::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use IAppConfig
lib/public/Util.php
Outdated
|
|
||
| $config = \OCP\Server::get(serviceName: IConfig::class); | ||
|
|
||
| $mailProvidersEnabled = $config->getAppValue('core', 'mail_providers_enabled', '0') === '1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $mailProvidersEnabled = $config->getAppValue('core', 'mail_providers_enabled', '0') === '1'; | |
| $mailProvidersEnabled = $appConfig->getValueBool('core', 'mail_providers_enabled', true) |
| ); | ||
| } | ||
| $message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]); | ||
| $fromAddress = Util::getDefaultEmailAddress(user_part: $instanceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you want to use the new function you added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have implemented appConfig directly here instead of creating a new function. If you prefer, I can shift this to a new function.
Signed-off-by: Abhinav Ohri <[email protected]>
| $mailProvidersEnabled = $this->appConfig->getValueBool('core', 'mail_providers_enabled'); | ||
| if ($mailProvidersEnabled && $this->mailManager->has()) { | ||
| if ($initiatorEmail !== null) { | ||
| $service = $this->mailManager->findServiceByAddress($initiator, $initiatorEmail); | ||
| if ($service !== null) { | ||
| $fromAddress = $service->getPrimaryAddress()->getAddress(); | ||
| } | ||
| } | ||
| } | ||
| $message->setFrom([$fromAddress => $senderName]); | ||
|
|
||
| // The "Reply-To" is set to the sharer if an mail address is configured | ||
| // also the default footer contains a "Do not reply" which needs to be adjusted. | ||
| if ($initiatorUser && $this->settingsManager->replyToInitiator()) { | ||
| $initiatorEmail = $initiatorUser->getEMailAddress(); | ||
| if ($initiatorEmail !== null) { | ||
| $message->setReplyTo([$initiatorEmail => $initiatorDisplayName]); | ||
| $emailTemplate->addFooter($instanceName . ($this->defaults->getSlogan() !== '' ? ' - ' . $this->defaults->getSlogan() : '')); | ||
| } else { | ||
| $emailTemplate->addFooter(); | ||
| } | ||
| } else { | ||
| $emailTemplate->addFooter(); | ||
| } | ||
|
|
||
| $message->useTemplate($emailTemplate); | ||
| $failedRecipients = $this->mailer->send($message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so you are pulling the mail service, but then you are just pulling the from address not actually sending the message using the mail provider. Your code is still using the system mailer to send the message, this will not work correctly.
Summary
This change allows to use the initiator's personal email as the sender email when sending share notifications, provided that the mail_providers_enabled configuration is active.
TODO
Checklist
3. to review, feature component)stable32)