Skip to content

Beautiful Open-Source Form Builder

Enhance Email Notification Sender Name Handling and Add Test Case (#780)

Chirag Chhatrala28daa968f4ec
diff --git a/api/app/Notifications/Forms/FormEmailNotification.php b/api/app/Notifications/Forms/FormEmailNotification.php
index d20eefa98..fd641a15a 100644
--- a/api/app/Notifications/Forms/FormEmailNotification.php
+++ b/api/app/Notifications/Forms/FormEmailNotification.php
@@ -129,7 +129,8 @@ class FormEmailNotification extends Notification
private function getSenderName(): string
{
- return $this->integrationData->sender_name ?? config('app.name');
+ $parser = new MentionParser($this->integrationData->sender_name ?? config('app.name'), $this->formatSubmissionData(false));
+ return $parser->parseAsText();
}
private function getReplyToEmail($default): string
diff --git a/api/tests/Feature/Forms/EmailNotificationTest.php b/api/tests/Feature/Forms/EmailNotificationTest.php
index 8e5c613c7..43e702621 100644
--- a/api/tests/Feature/Forms/EmailNotificationTest.php
+++ b/api/tests/Feature/Forms/EmailNotificationTest.php
@@ -165,6 +165,37 @@ it('does not use custom sender email in non-self-hosted mode', function () {
expect(trim($renderedMail->render()))->toContain('Custom content');
});
+it('send email with mention as sender name', function () {
+ $user = $this->actingAsUser();
+ $workspace = $this->createUserWorkspace($user);
+ $form = $this->createForm($user, $workspace);
+
+ $emailProperty = collect($form->properties)->first(function ($property) {
+ return $property['type'] == 'email';
+ });
+
+ $integrationData = $this->createFormIntegration('email', $form->id, [
+ 'send_to' => '[email protected]',
+ 'sender_name' => '<span mention-field-id="' . $emailProperty['id'] . '" mention-field-name="' . $emailProperty['name'] . '" mention-fallback="" contenteditable="false" mention="true">' . $emailProperty['name'] . '</span>',
+ 'subject' => 'New form submission',
+ 'email_content' => 'Hello there 👋 <br>Test body',
+ 'include_submission_data' => true,
+ 'include_hidden_fields_submission_data' => false,
+ 'reply_to' => null
+ ]);
+
+ $formData = [
+ $emailProperty['id'] => '[email protected]',
+ ];
+
+ $event = new \App\Events\Forms\FormSubmitted($form, $formData);
+ $mailable = new FormEmailNotification($event, $integrationData, 'mail');
+ $notifiable = new AnonymousNotifiable();
+ $notifiable->route('mail', '[email protected]');
+ $renderedMail = $mailable->toMail($notifiable);
+ expect($renderedMail->from[1])->toBe('[email protected]');
+});
+
it('send email with mention as reply to', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
diff --git a/client/components/open/integrations/EmailIntegration.vue b/client/components/open/integrations/EmailIntegration.vue
index a03c5d882..dc6091552 100644
--- a/client/components/open/integrations/EmailIntegration.vue
+++ b/client/components/open/integrations/EmailIntegration.vue
@@ -24,8 +24,9 @@
help="Add one email per line"
/>
<div class="flex space-x-4">
- <text-input
+ <MentionInput
:form="integrationData"
+ :mentions="form.properties"
name="settings.sender_name"
label="Sender Name"
class="flex-1"