Send an email using the specified settings to notify a new OAuth signup.
Source code in fractal_server/app/security/signup_email.py
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | def mail_new_oauth_signup(msg: str, mail_settings: MailSettings):
"""
Send an email using the specified settings to notify a new OAuth signup.
"""
mail_msg = EmailMessage()
mail_msg.set_content(msg)
mail_msg["From"] = formataddr((mail_settings.sender, mail_settings.sender))
mail_msg["To"] = ",".join(
[
formataddr((recipient, recipient))
for recipient in mail_settings.recipients
]
)
mail_msg[
"Subject"
] = f"[Fractal, {mail_settings.instance_name}] New OAuth signup"
with smtplib.SMTP(mail_settings.smtp_server, mail_settings.port) as server:
server.ehlo()
if mail_settings.use_starttls:
server.starttls()
server.ehlo()
server.login(
user=mail_settings.sender, password=mail_settings.password
)
server.sendmail(
from_addr=mail_settings.sender,
to_addrs=mail_settings.recipients,
msg=mail_msg.as_string(),
)
|