wysylka maili
This commit is contained in:
		
							
								
								
									
										33
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								app.py
									
									
									
									
									
								
							@@ -155,20 +155,18 @@ def days_to_years(days):
 | 
			
		||||
    return round(days / 365, 1)
 | 
			
		||||
 | 
			
		||||
def get_smtp_config():
 | 
			
		||||
    required_keys = ["SMTP_HOST", "SMTP_PORT", "SMTP_USER", "SMTP_PASSWORD"]
 | 
			
		||||
    config = {key: os.getenv(key) for key in required_keys}
 | 
			
		||||
 | 
			
		||||
    missing = [k for k, v in config.items() if not v]
 | 
			
		||||
    if missing:
 | 
			
		||||
        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"]
 | 
			
		||||
    config = {
 | 
			
		||||
        "host": os.getenv("SMTP_HOST"),
 | 
			
		||||
        "port": os.getenv("SMTP_PORT"),
 | 
			
		||||
        "user": os.getenv("SMTP_USER"),
 | 
			
		||||
        "password": os.getenv("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):
 | 
			
		||||
    import os
 | 
			
		||||
 | 
			
		||||
@@ -186,8 +184,15 @@ def send_email_batch(users, smtp_config, mails_per_pack=100, time_per_pack=60, d
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        smtp = smtplib.SMTP(smtp_config["host"], int(smtp_config["port"]))
 | 
			
		||||
        smtp.starttls()
 | 
			
		||||
        smtp.login(smtp_config["user"], smtp_config["password"])
 | 
			
		||||
        smtp.ehlo()
 | 
			
		||||
        try:
 | 
			
		||||
            smtp.starttls()
 | 
			
		||||
            smtp.ehlo()
 | 
			
		||||
        except Exception:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
        if smtp_config["user"] and smtp_config["password"]:
 | 
			
		||||
            smtp.login(smtp_config["user"], smtp_config["password"])
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        print(f"❌ Błąd połączenia z serwerem SMTP: {e}")
 | 
			
		||||
        return
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user