wysylka maili
This commit is contained in:
parent
c311096e05
commit
f03bd964b2
29
app.py
29
app.py
@ -155,20 +155,18 @@ def days_to_years(days):
|
|||||||
return round(days / 365, 1)
|
return round(days / 365, 1)
|
||||||
|
|
||||||
def get_smtp_config():
|
def get_smtp_config():
|
||||||
required_keys = ["SMTP_HOST", "SMTP_PORT", "SMTP_USER", "SMTP_PASSWORD"]
|
config = {
|
||||||
config = {key: os.getenv(key) for key in required_keys}
|
"host": os.getenv("SMTP_HOST"),
|
||||||
|
"port": os.getenv("SMTP_PORT"),
|
||||||
missing = [k for k, v in config.items() if not v]
|
"user": os.getenv("SMTP_USER"),
|
||||||
if missing:
|
"password": os.getenv("SMTP_PASSWORD")
|
||||||
raise ValueError(f"❌ Brakuje wymaganych zmiennych SMTP w pliku .env: {', '.join(missing)}")
|
|
||||||
|
|
||||||
return {
|
|
||||||
"host": config["SMTP_HOST"],
|
|
||||||
"port": config["SMTP_PORT"],
|
|
||||||
"user": config["SMTP_USER"],
|
|
||||||
"password": config["SMTP_PASSWORD"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if not config["host"] or not config["port"]:
|
||||||
|
raise ValueError("❌ Brakuje SMTP_HOST lub SMTP_PORT w .env")
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
def send_email_batch(users, smtp_config, mails_per_pack=100, time_per_pack=60, dry_run=False):
|
def send_email_batch(users, smtp_config, mails_per_pack=100, time_per_pack=60, dry_run=False):
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -186,7 +184,14 @@ def send_email_batch(users, smtp_config, mails_per_pack=100, time_per_pack=60, d
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
smtp = smtplib.SMTP(smtp_config["host"], int(smtp_config["port"]))
|
smtp = smtplib.SMTP(smtp_config["host"], int(smtp_config["port"]))
|
||||||
|
smtp.ehlo()
|
||||||
|
try:
|
||||||
smtp.starttls()
|
smtp.starttls()
|
||||||
|
smtp.ehlo()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if smtp_config["user"] and smtp_config["password"]:
|
||||||
smtp.login(smtp_config["user"], smtp_config["password"])
|
smtp.login(smtp_config["user"], smtp_config["password"])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ Błąd połączenia z serwerem SMTP: {e}")
|
print(f"❌ Błąd połączenia z serwerem SMTP: {e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user