Skip to content

Commit 69a84fd

Browse files
authored
Smtp settings (#16)
* move smtp config to settings * fix pre-commit config * lint fix
1 parent 5b8734a commit 69a84fd

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ repos:
1414
- id: black
1515
files: ^backend/
1616
args:
17+
- --check
1718
- --diff
1819

1920
- repo: https://github.com/pycqa/isort
@@ -22,4 +23,5 @@ repos:
2223
- id: isort
2324
files: ^backend/
2425
args:
26+
- --check-only
2527
- --diff

backend/backlog_app/config.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import Literal
44

5-
from pydantic import AmqpDsn, BaseModel, field_validator
5+
from pydantic import AmqpDsn, BaseModel, EmailStr, field_validator
66
from pydantic_settings import (
77
BaseSettings,
88
PydanticBaseSettingsSource,
@@ -36,10 +36,18 @@ class AccessToken(BaseModel):
3636

3737

3838
class SuperUser(BaseModel):
39-
email: str
39+
email: EmailStr
4040
password: str
4141

4242

43+
class SMTPConfig(BaseModel):
44+
username: EmailStr
45+
password: str
46+
server: str
47+
port: int
48+
use_tls: bool = True
49+
50+
4351
class DataBaseConnection(BaseModel):
4452
host: str
4553
port: int
@@ -118,6 +126,7 @@ def settings_customise_sources(
118126
logging: LoggingConfig = LoggingConfig()
119127
access_token_db: AccessToken
120128
superuser: SuperUser
129+
smtp: SMTPConfig
121130
cors_origins: list[str] = ["http://localhost:5173"]
122131

123132

backend/backlog_app/servicies/mailing/email_sender.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33

44
import aiosmtplib
55

6+
from backlog_app.config import settings
7+
68

79
async def send_email(
810
recipient: str,
911
subject: str,
1012
plain_content: str,
1113
html_content: str = "",
1214
):
13-
admin_email = "admin@site.com" # todo: перенести в настройки
1415
message = MIMEMultipart("alternative")
15-
message["From"] = admin_email
16+
message["From"] = settings.smtp.username
1617
message["To"] = recipient
1718
message["Subject"] = subject
1819

@@ -31,4 +32,11 @@ async def send_email(
3132
)
3233
message.attach(html_message)
3334

34-
await aiosmtplib.send(message, hostname="127.0.0.1", port=1025)
35+
await aiosmtplib.send(
36+
message,
37+
hostname=settings.smtp.server,
38+
port=settings.smtp.port,
39+
use_tls=settings.smtp.use_tls,
40+
username=settings.smtp.username,
41+
password=settings.smtp.password,
42+
)

backend/config.default.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ backlog:
44
- http://127.0.0.1
55
logging:
66
log_level_name: INFO
7+
smtp:
8+
username: noreply@site.com
9+
password: noreply
10+
smtp_server: 127.0.0.1
11+
smtp_port: 1025
12+
use_tls: False

0 commit comments

Comments
 (0)