File size: 1,682 Bytes
1c84ad3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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 = "noreply@aideatext.ai"  # Configura esto con tu direcci贸n de correo
    receiver_email = "hello@aideatext.ai"
    password = os.environ.get("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.gmail.com", 465) as server:
            server.login(sender_email, password)
            server.sendmail(sender_email, receiver_email, message.as_string())
        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