feat: add free email sending with Resend API
Browse files- app/main.py +19 -23
- app/requirements.txt +7 -5
app/main.py
CHANGED
|
@@ -18,9 +18,7 @@ import telebot
|
|
| 18 |
from telebot import types
|
| 19 |
import markdown
|
| 20 |
from dotenv import load_dotenv
|
| 21 |
-
import
|
| 22 |
-
from email.mime.text import MIMEText
|
| 23 |
-
from email.mime.multipart import MIMEMultipart
|
| 24 |
|
| 25 |
# Cargar variables de entorno desde .env
|
| 26 |
load_dotenv()
|
|
@@ -419,31 +417,29 @@ def logout():
|
|
| 419 |
return redirect(url_for('index'))
|
| 420 |
|
| 421 |
def send_email(to_email, subject, body):
|
| 422 |
-
"""Envía un correo electrónico usando
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
if not all([smtp_server, smtp_port, smtp_user, smtp_password]):
|
| 429 |
-
print("[EMAIL ERROR] Falta configuración SMTP en variables de entorno.")
|
| 430 |
return False
|
| 431 |
|
| 432 |
try:
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
return True
|
| 445 |
except Exception as e:
|
| 446 |
-
print(f"[EMAIL ERROR] Error enviando correo: {e}")
|
| 447 |
return False
|
| 448 |
|
| 449 |
@app.route('/forgot-password', methods=['GET', 'POST'])
|
|
|
|
| 18 |
from telebot import types
|
| 19 |
import markdown
|
| 20 |
from dotenv import load_dotenv
|
| 21 |
+
import resend
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Cargar variables de entorno desde .env
|
| 24 |
load_dotenv()
|
|
|
|
| 417 |
return redirect(url_for('index'))
|
| 418 |
|
| 419 |
def send_email(to_email, subject, body):
|
| 420 |
+
"""Envía un correo electrónico usando Resend (100% gratis hasta 100 emails/día)."""
|
| 421 |
+
resend_api_key = os.getenv("RESEND_API_KEY")
|
| 422 |
+
from_email = os.getenv("FROM_EMAIL", "onboarding@resend.dev") # Email verificado en Resend
|
| 423 |
+
|
| 424 |
+
if not resend_api_key:
|
| 425 |
+
print("[EMAIL ERROR] Falta RESEND_API_KEY en variables de entorno.")
|
|
|
|
|
|
|
| 426 |
return False
|
| 427 |
|
| 428 |
try:
|
| 429 |
+
resend.api_key = resend_api_key
|
| 430 |
+
|
| 431 |
+
params = {
|
| 432 |
+
"from": from_email,
|
| 433 |
+
"to": [to_email],
|
| 434 |
+
"subject": subject,
|
| 435 |
+
"text": body,
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
email_response = resend.Emails.send(params)
|
| 439 |
+
print(f"[EMAIL SUCCESS] Correo enviado a {to_email}: {email_response}")
|
| 440 |
return True
|
| 441 |
except Exception as e:
|
| 442 |
+
print(f"[EMAIL ERROR] Error enviando correo con Resend: {e}")
|
| 443 |
return False
|
| 444 |
|
| 445 |
@app.route('/forgot-password', methods=['GET', 'POST'])
|
app/requirements.txt
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
flask
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
pyTelegramBotAPI
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
gunicorn
|
| 8 |
eventlet
|
| 9 |
markdown
|
|
|
|
| 1 |
flask
|
| 2 |
+
fFlask-SocketIO==5.3.4
|
| 3 |
+
eventlet==0.33.3
|
| 4 |
+
python-gitlab==3.15.0
|
| 5 |
+
pyTelegramBotAPI==4.12.0
|
| 6 |
+
markdown==3.4.4
|
| 7 |
+
python-dotenv==1.0.0
|
| 8 |
+
resend==0.8.0
|
| 9 |
gunicorn
|
| 10 |
eventlet
|
| 11 |
markdown
|