Spaces:
Running
Running
| import smtplib | |
| from email.mime.text import MIMEText | |
| from email.mime.multipart import MIMEMultipart | |
| import os | |
| def send_email_notification(name, email, institution, role, reason): | |
| sender_email = "[email protected]" # Configura esto con tu direcci贸n de correo | |
| receiver_email = "[email protected]" | |
| password = os.environ.get("NOREPLY_EMAIL_PASSWORD") # Configura esto en tus variables de entorno | |
| message = MIMEMultipart("alternative") | |
| message["Subject"] = "Nueva solicitud de prueba de AIdeaText" | |
| message["From"] = sender_email | |
| message["To"] = receiver_email | |
| text = f"""\ | |
| Nueva solicitud de prueba de AIdeaText: | |
| Nombre: {name} | |
| Email: {email} | |
| Instituci贸n: {institution} | |
| Rol: {role} | |
| Raz贸n: {reason} | |
| """ | |
| html = f"""\ | |
| <html> | |
| <body> | |
| <h2>Nueva solicitud de prueba de AIdeaText</h2> | |
| <p><strong>Nombre:</strong> {name}</p> | |
| <p><strong>Email:</strong> {email}</p> | |
| <p><strong>Instituci贸n:</strong> {institution}</p> | |
| <p><strong>Rol:</strong> {role}</p> | |
| <p><strong>Raz贸n:</strong> {reason}</p> | |
| </body> | |
| </html> | |
| """ | |
| part1 = MIMEText(text, "plain") | |
| part2 = MIMEText(html, "html") | |
| message.attach(part1) | |
| message.attach(part2) | |
| try: | |
| with smtplib.SMTP_SSL("smtp.titan.email", 465) as server: | |
| logger.info("Conectado al servidor SMTP") | |
| server.login(sender_email, password) | |
| logger.info("Inicio de sesi贸n exitoso") | |
| server.sendmail(sender_email, receiver_email, message.as_string()) | |
| logger.info(f"Correo enviado de {sender_email} a {receiver_email}") | |
| logger.info(f"Email notification sent for application request: {email}") | |
| return True | |
| except Exception as e: | |
| logger.error(f"Error sending email notification: {str(e)}") | |
| return False | |
| def send_user_feedback_notification(name, email, feedback): | |
| sender_email = "[email protected]" | |
| receiver_email = "[email protected]" # Cambia esto a la direcci贸n que desees | |
| password = os.environ.get("NOREPLY_EMAIL_PASSWORD") | |
| message = MIMEMultipart("alternative") | |
| message["Subject"] = "Nuevo comentario de usuario en AIdeaText" | |
| message["From"] = sender_email | |
| message["To"] = receiver_email | |
| html = f"""\ | |
| <html> | |
| <body> | |
| <h2>Nuevo comentario de usuario en AIdeaText</h2> | |
| <p><strong>Nombre:</strong> {name}</p> | |
| <p><strong>Email:</strong> {email}</p> | |
| <p><strong>Comentario:</strong> {feedback}</p> | |
| </body> | |
| </html> | |
| """ | |
| part = MIMEText(html, "html") | |
| message.attach(part) | |
| try: | |
| with smtplib.SMTP_SSL("smtp.titan.email", 465) as server: | |
| logger.info("Conectado al servidor SMTP") | |
| server.login(sender_email, password) | |
| logger.info("Inicio de sesi贸n exitoso") | |
| server.sendmail(sender_email, receiver_email, message.as_string()) | |
| logger.info(f"Correo enviado de {sender_email} a {receiver_email}") | |
| logger.info(f"Email notification sent for user feedback from: {email}") | |
| return True | |
| except Exception as e: | |
| logger.error(f"Error sending user feedback email notification: {str(e)}") | |
| return False |