Skip to content

Commit 9b066bc

Browse files
FEATURE (email): Add "from" field
1 parent 9ea795b commit 9b066bc

File tree

7 files changed

+55
-3
lines changed

7 files changed

+55
-3
lines changed

backend/internal/features/notifiers/models/email_notifier/model.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type EmailNotifier struct {
2727
SMTPPort int `json:"smtpPort" gorm:"not null;column:smtp_port"`
2828
SMTPUser string `json:"smtpUser" gorm:"type:varchar(255);column:smtp_user"`
2929
SMTPPassword string `json:"smtpPassword" gorm:"type:varchar(255);column:smtp_password"`
30+
From string `json:"from" gorm:"type:varchar(255);column:from_email"`
3031
}
3132

3233
func (e *EmailNotifier) TableName() string {
@@ -56,9 +57,12 @@ func (e *EmailNotifier) Validate() error {
5657

5758
func (e *EmailNotifier) Send(logger *slog.Logger, heading string, message string) error {
5859
// Compose email
59-
from := e.SMTPUser
60+
from := e.From
6061
if from == "" {
61-
from = "noreply@" + e.SMTPHost
62+
from = e.SMTPUser
63+
if from == "" {
64+
from = "noreply@" + e.SMTPHost
65+
}
6266
}
6367

6468
to := []string{e.TargetEmail}
@@ -218,6 +222,7 @@ func (e *EmailNotifier) Update(incoming *EmailNotifier) {
218222
e.SMTPHost = incoming.SMTPHost
219223
e.SMTPPort = incoming.SMTPPort
220224
e.SMTPUser = incoming.SMTPUser
225+
e.From = incoming.From
221226

222227
if incoming.SMTPPassword != "" {
223228
e.SMTPPassword = incoming.SMTPPassword
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE email_notifiers
4+
ADD COLUMN from_email VARCHAR(255);
5+
-- +goose StatementEnd
6+
7+
-- +goose Down
8+
-- +goose StatementBegin
9+
ALTER TABLE email_notifiers
10+
DROP COLUMN from_email;
11+
-- +goose StatementEnd

frontend/src/entity/notifiers/models/email/EmailNotifier.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface EmailNotifier {
44
smtpPort: number;
55
smtpUser: string;
66
smtpPassword: string;
7+
from: string;
78
}

frontend/src/features/backups/ui/BackupsComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { getUserTimeFormat } from '../../../shared/time';
2525
import { ConfirmationComponent } from '../../../shared/ui';
2626
import { RestoresComponent } from '../../restores';
2727

28-
const BACKUPS_PAGE_SIZE = 10;
28+
const BACKUPS_PAGE_SIZE = 50;
2929

3030
interface Props {
3131
database: Database;

frontend/src/features/notifiers/ui/edit/EditNotifierComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function EditNotifierComponent({
111111
smtpPort: 0,
112112
smtpUser: '',
113113
smtpPassword: '',
114+
from: '',
114115
};
115116
}
116117

frontend/src/features/notifiers/ui/edit/notifiers/EditEmailNotifierComponent.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@ export function EditEmailNotifierComponent({ notifier, setNotifier, setIsUnsaved
126126
placeholder="password"
127127
/>
128128
</div>
129+
130+
<div className="mb-1 flex items-center">
131+
<div className="w-[130px] min-w-[130px]">From</div>
132+
<Input
133+
value={notifier?.emailNotifier?.from || ''}
134+
onChange={(e) => {
135+
if (!notifier?.emailNotifier) return;
136+
137+
setNotifier({
138+
...notifier,
139+
emailNotifier: {
140+
...notifier.emailNotifier,
141+
from: e.target.value.trim(),
142+
},
143+
});
144+
setIsUnsaved(true);
145+
}}
146+
size="small"
147+
className="w-full max-w-[250px]"
148+
placeholder="[email protected]"
149+
/>
150+
151+
<Tooltip
152+
className="cursor-pointer"
153+
title="Optional. Email address to use as sender. If empty, will use SMTP user or auto-generate from host"
154+
>
155+
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
156+
</Tooltip>
157+
</div>
129158
</>
130159
);
131160
}

frontend/src/features/notifiers/ui/show/notifier/ShowEmailNotifierComponent.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export function ShowEmailNotifierComponent({ notifier }: Props) {
3131
<div className="min-w-[110px]">SMTP password</div>
3232
{'*************'}
3333
</div>
34+
35+
<div className="mb-1 flex items-center">
36+
<div className="min-w-[110px]">From</div>
37+
{notifier?.emailNotifier?.from || '(auto)'}
38+
</div>
3439
</>
3540
);
3641
}

0 commit comments

Comments
 (0)