diff --git a/config.py b/config.py index aff16fc..0dd5315 100644 --- a/config.py +++ b/config.py @@ -1,2 +1,9 @@ ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} -MAX_FILE_SIZE = 5 * 1024 * 1024 # 5 MB \ No newline at end of file +MAX_FILE_SIZE = 5 * 1024 * 1024 # 5 MB + +USE_EXTERNAL_SMTP = False +SMTP_SERVER = 'smtp.example.com' +SMTP_PORT = 587 +SMTP_USE_TLS = True +SMTP_SENDER_EMAIL = 'your_email@example.com' +SMTP_SENDER_PASSWORD = 'your_email_password' \ No newline at end of file diff --git a/utils.py b/utils.py index 326d970..64031a5 100644 --- a/utils.py +++ b/utils.py @@ -14,21 +14,32 @@ def generate_password(length=10): return ''.join(random.choice(characters) for _ in range(length)) def send_email(recipient_email, subject, body): - sender_email = "your_email@example.com" - sender_password = "your_email_password" + if config.USE_EXTERNAL_SMTP: + sender_email = config.SMTP_SENDER_EMAIL + sender_password = config.SMTP_SENDER_PASSWORD - msg = MIMEText(body) - msg['Subject'] = subject - msg['From'] = sender_email - msg['To'] = recipient_email + msg = MIMEText(body) + msg['Subject'] = subject + msg['From'] = sender_email + msg['To'] = recipient_email - try: - with smtplib.SMTP('smtp.gmail.com', 587) as server: - server.starttls() - server.login(sender_email, sender_password) - server.send_message(msg) - except Exception as e: - print(f"Failed to send email: {e}") + try: + with smtplib.SMTP(config.SMTP_SERVER, config.SMTP_PORT) as server: + if config.SMTP_USE_TLS: + server.starttls() + server.login(sender_email, sender_password) + server.send_message(msg) + except Exception as e: + print(f"Failed to send email via external SMTP: {e}") + else: + try: + process = os.popen(f"/usr/sbin/sendmail -t") + process.write(f"To: {recipient_email}\n") + process.write(f"Subject: {subject}\n") + process.write(f"\n{body}") + process.close() + except Exception as e: + print(f"Failed to send email via local sendmail: {e}") def is_file_allowed(file): return '.' in file.filename and file.filename.rsplit('.', 1)[1].lower() in config.ALLOWED_EXTENSIONS