feat(sharebymail): Use initiator's email as sender if mail providers enabled#57080
feat(sharebymail): Use initiator's email as sender if mail providers enabled#57080abhinavohri wants to merge 2 commits intonextcloud:masterfrom
Conversation
…enabled Signed-off-by: Abhinav Ohri <abhinavohri13@gmail.com>
tcitworld
left a comment
There was a problem hiding this comment.
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.
| * @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.
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); |
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.
| $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.
I assume you want to use the new function you added here?
There was a problem hiding this comment.
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 <abhinavohri13@gmail.com>
| $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.
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.
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
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)