arpakitlib 1.8.158__py3-none-any.whl → 1.8.159__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arpakitlib/_arpakit_project_template_v_5/project/util/send_email_.py +38 -12
- {arpakitlib-1.8.158.dist-info → arpakitlib-1.8.159.dist-info}/METADATA +1 -1
- {arpakitlib-1.8.158.dist-info → arpakitlib-1.8.159.dist-info}/RECORD +6 -6
- {arpakitlib-1.8.158.dist-info → arpakitlib-1.8.159.dist-info}/LICENSE +0 -0
- {arpakitlib-1.8.158.dist-info → arpakitlib-1.8.159.dist-info}/WHEEL +0 -0
- {arpakitlib-1.8.158.dist-info → arpakitlib-1.8.159.dist-info}/entry_points.txt +0 -0
@@ -4,6 +4,7 @@ import logging
|
|
4
4
|
import smtplib
|
5
5
|
import ssl
|
6
6
|
from email.message import EmailMessage
|
7
|
+
from email.utils import formataddr
|
7
8
|
|
8
9
|
import aiosmtplib
|
9
10
|
|
@@ -13,9 +14,19 @@ from project.core.util import setup_logging
|
|
13
14
|
_logger = logging.getLogger(__name__)
|
14
15
|
|
15
16
|
|
16
|
-
def
|
17
|
+
def _build_email_message(
|
18
|
+
*,
|
19
|
+
from_email: str,
|
20
|
+
to_email: str,
|
21
|
+
subject: str,
|
22
|
+
html_content: str,
|
23
|
+
from_name: str | None = None,
|
24
|
+
) -> EmailMessage:
|
17
25
|
msg = EmailMessage()
|
18
|
-
|
26
|
+
if from_name:
|
27
|
+
msg["From"] = formataddr((from_name, from_email))
|
28
|
+
else:
|
29
|
+
msg["From"] = from_email # без имени
|
19
30
|
msg["To"] = to_email.strip()
|
20
31
|
msg["Subject"] = subject
|
21
32
|
msg.add_alternative(html_content, subtype="html")
|
@@ -24,6 +35,7 @@ def _build_message(to_email: str, subject: str, html_content: str) -> EmailMessa
|
|
24
35
|
|
25
36
|
def sync_send_email(
|
26
37
|
*,
|
38
|
+
from_name: str | None = get_cached_settings().project_name,
|
27
39
|
to_email: str,
|
28
40
|
subject: str = get_cached_settings().project_name,
|
29
41
|
html_content: str,
|
@@ -33,26 +45,32 @@ def sync_send_email(
|
|
33
45
|
_logger.info(f"emulate email sending, to_email={to_email!r}, subject={subject!r}")
|
34
46
|
return
|
35
47
|
|
48
|
+
message = _build_email_message(
|
49
|
+
from_email=get_cached_settings().email_smtp_user,
|
50
|
+
from_name=from_name,
|
51
|
+
to_email=to_email, subject=subject, html_content=html_content
|
52
|
+
)
|
53
|
+
|
36
54
|
if get_cached_settings().email_smtp_port == 465:
|
37
55
|
_logger.info("using port 465 (SSL)")
|
38
56
|
with smtplib.SMTP_SSL(
|
39
57
|
host=get_cached_settings().email_smtp_hostname,
|
40
58
|
port=465,
|
41
|
-
timeout=dt.timedelta(seconds=
|
59
|
+
timeout=dt.timedelta(seconds=15).total_seconds(),
|
42
60
|
context=ssl.create_default_context(),
|
43
61
|
) as server:
|
44
62
|
server.login(
|
45
63
|
get_cached_settings().email_smtp_user,
|
46
64
|
get_cached_settings().email_smtp_password,
|
47
65
|
)
|
48
|
-
server.send_message(
|
66
|
+
server.send_message(message)
|
49
67
|
|
50
68
|
elif get_cached_settings().email_smtp_port == 587:
|
51
69
|
_logger.info("using port 587 (STARTTLS)")
|
52
70
|
with smtplib.SMTP(
|
53
71
|
host=get_cached_settings().email_smtp_hostname,
|
54
72
|
port=587,
|
55
|
-
timeout=dt.timedelta(seconds=
|
73
|
+
timeout=dt.timedelta(seconds=15).total_seconds(),
|
56
74
|
) as server:
|
57
75
|
server.ehlo()
|
58
76
|
server.starttls(context=ssl.create_default_context())
|
@@ -61,7 +79,7 @@ def sync_send_email(
|
|
61
79
|
get_cached_settings().email_smtp_user,
|
62
80
|
get_cached_settings().email_smtp_password,
|
63
81
|
)
|
64
|
-
server.send_message(
|
82
|
+
server.send_message(message)
|
65
83
|
else:
|
66
84
|
raise ValueError("Unsupported SMTP port")
|
67
85
|
|
@@ -70,6 +88,7 @@ def sync_send_email(
|
|
70
88
|
|
71
89
|
async def async_send_email(
|
72
90
|
*,
|
91
|
+
from_name: str | None = get_cached_settings().project_name,
|
73
92
|
to_email: str,
|
74
93
|
subject: str = get_cached_settings().project_name,
|
75
94
|
html_content: str,
|
@@ -79,31 +98,37 @@ async def async_send_email(
|
|
79
98
|
_logger.info(f"emulate email sending, to_email={to_email!r}, subject={subject!r}")
|
80
99
|
return
|
81
100
|
|
101
|
+
message = _build_email_message(
|
102
|
+
from_email=get_cached_settings().email_smtp_user,
|
103
|
+
from_name=from_name,
|
104
|
+
to_email=to_email, subject=subject, html_content=html_content
|
105
|
+
)
|
106
|
+
|
82
107
|
if get_cached_settings().email_smtp_port == 465:
|
83
108
|
_logger.info("using port 465 (SSL)")
|
84
109
|
await aiosmtplib.send(
|
85
|
-
|
110
|
+
message,
|
86
111
|
hostname=get_cached_settings().email_smtp_hostname,
|
87
|
-
port=
|
112
|
+
port=465,
|
88
113
|
username=get_cached_settings().email_smtp_user,
|
89
114
|
password=get_cached_settings().email_smtp_password,
|
90
115
|
use_tls=True,
|
91
116
|
start_tls=False,
|
92
|
-
timeout=dt.timedelta(seconds=
|
117
|
+
timeout=dt.timedelta(seconds=15).total_seconds(),
|
93
118
|
tls_context=ssl.create_default_context(),
|
94
119
|
)
|
95
120
|
|
96
121
|
elif get_cached_settings().email_smtp_port == 587:
|
97
122
|
_logger.info("using port 587 (STARTTLS)")
|
98
123
|
await aiosmtplib.send(
|
99
|
-
|
124
|
+
message,
|
100
125
|
hostname=get_cached_settings().email_smtp_hostname,
|
101
|
-
port=
|
126
|
+
port=587,
|
102
127
|
username=get_cached_settings().email_smtp_user,
|
103
128
|
password=get_cached_settings().email_smtp_password,
|
104
129
|
use_tls=False,
|
105
130
|
start_tls=True,
|
106
|
-
timeout=dt.timedelta(seconds=
|
131
|
+
timeout=dt.timedelta(seconds=15).total_seconds(),
|
107
132
|
tls_context=ssl.create_default_context(),
|
108
133
|
)
|
109
134
|
else:
|
@@ -117,6 +142,7 @@ async def __async_example():
|
|
117
142
|
await async_send_email(
|
118
143
|
to_email="arpakit@gmail.com",
|
119
144
|
html_content="Hello world 2",
|
145
|
+
from_name="Gamer Market"
|
120
146
|
)
|
121
147
|
|
122
148
|
|
@@ -359,7 +359,7 @@ arpakitlib/_arpakit_project_template_v_5/project/tg_bot_notifier/tg_bot_notifier
|
|
359
359
|
arpakitlib/_arpakit_project_template_v_5/project/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
360
360
|
arpakitlib/_arpakit_project_template_v_5/project/util/arpakitlib_project_template_util.py,sha256=syA_IuszHVub0zm0sVdB4_7rPJXwXRW4JmQ4qHbjXPk,396
|
361
361
|
arpakitlib/_arpakit_project_template_v_5/project/util/etc.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
362
|
-
arpakitlib/_arpakit_project_template_v_5/project/util/send_email_.py,sha256=
|
362
|
+
arpakitlib/_arpakit_project_template_v_5/project/util/send_email_.py,sha256=ZfJkdCxyZhbNs4A2FgOQcath75BtJLLIhMFwYhVxmqg,4707
|
363
363
|
arpakitlib/_arpakit_project_template_v_5/todo.txt,sha256=q132Jbx229ThY77S3YiN-Cj5AVm7k1VlJcMYIbZUHUY,3
|
364
364
|
arpakitlib/ar_additional_model_util.py,sha256=GFg-glLCxH9X95R2bhTJsscVwv37FgE1qbaAAyXrnIE,917
|
365
365
|
arpakitlib/ar_aiogram_util.py,sha256=4bizX5Xg-E2-r2TXXGQGanJozsIWPVf5luO3vKUN8p8,8471
|
@@ -408,8 +408,8 @@ arpakitlib/ar_ssh_runner_util.py,sha256=yvAwza480MkHKvLkDEsR7JNh2bYNs6P9rCVo4NA8
|
|
408
408
|
arpakitlib/ar_str_util.py,sha256=2lGpnXDf2h1cBZpVf5i1tX_HCv5iBd6IGnrCw4QWWlY,4350
|
409
409
|
arpakitlib/ar_type_util.py,sha256=Cs_tef-Fc5xeyAF54KgISCsP11NHyzIsglm4S3Xx7iM,4049
|
410
410
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=VozuZeCJjmLd1zj2BdC9WfiAQ3XYOrIMsdpNK-AUlm0,5347
|
411
|
-
arpakitlib-1.8.
|
412
|
-
arpakitlib-1.8.
|
413
|
-
arpakitlib-1.8.
|
414
|
-
arpakitlib-1.8.
|
415
|
-
arpakitlib-1.8.
|
411
|
+
arpakitlib-1.8.159.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
412
|
+
arpakitlib-1.8.159.dist-info/METADATA,sha256=jHymW1AC6wM8BZW-PSxW_USIXesFIPr6GYZW5P8Ey6k,3706
|
413
|
+
arpakitlib-1.8.159.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
414
|
+
arpakitlib-1.8.159.dist-info/entry_points.txt,sha256=36xqR3PJFT2kuwjkM_EqoIy0qFUDPKSm_mJaI7emewE,87
|
415
|
+
arpakitlib-1.8.159.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|