email_service.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import smtplib
  2. from email.message import EmailMessage
  3. def send_email():
  4. """Send email notification when printer is disconnected"""
  5. # Datos del remitente
  6. EMAIL_ORIGEN = 'expresspedidos211@gmail.com'
  7. EMAIL_DESTINO = ['erwinjacimino2003@gmail.com', "mompyn@gmail.com"]
  8. CONTRASENA = 'drkassszdtgapufg'
  9. # Crear el correo
  10. msg = EmailMessage()
  11. msg['Subject'] = 'Impresora Desconectada weon :('
  12. msg['From'] = EMAIL_ORIGEN
  13. msg['To'] = ", ".join(EMAIL_DESTINO)
  14. msg.set_content('Este correo tiene contenido HTML.')
  15. msg.add_alternative("""
  16. <html>
  17. <body style="margin:0; padding:0; background-color:#5a67d8; font-family: Arial, sans-serif;">
  18. <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%" style="padding: 40px 0;">
  19. <tr>
  20. <td align="center">
  21. <table border="0" cellpadding="0" cellspacing="0" width="500" style="background-color: #e3e3e3; border-radius: 25px; padding: 40px; text-align: center;">
  22. <tr>
  23. <td>
  24. <div style="font-size: 60px; background-color: #ff6b6b; width: 80px; height: 80px; line-height: 80px; border-radius: 15px; margin: 0 auto 20px; color: white;">
  25. 🖨️
  26. </div>
  27. </td>
  28. </tr>
  29. <tr>
  30. <td>
  31. <img src="https://media4.giphy.com/media/v1.Y2lkPTc5MGI3NjExZGlraDhpb2tkeHEweDZ2eWdnZDZlNXFvODhmNzZieWN6OXp0b3ZqNCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3hetVnNSl0IBa/giphy.gif" alt="Gatito peleando con la impresora" width="250" style="border-radius: 12px; margin-bottom: 20px;" />
  32. </td>
  33. </tr>
  34. <tr>
  35. <td>
  36. <h1 style="font-size: 24px; color: #ff6b6b; margin-bottom: 10px;">¡Impresora Desconectada!</h1>
  37. </td>
  38. </tr>
  39. <tr>
  40. <td>
  41. <p style="font-size: 16px; color: #333333; line-height: 1.5; margin-bottom: 20px;">
  42. No se puede establecer conexión con la impresora.<br>
  43. Por favor, verifica la conexión y vuelve a intentarlo.
  44. </p>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td>
  49. <span style="display: inline-block; background: #ff6b6b; color: white; padding: 12px 24px; border-radius: 25px; font-weight: bold; font-size: 16px;">
  50. 🔴 Estado: Desconectada
  51. </span>
  52. </td>
  53. </tr>
  54. </table>
  55. </td>
  56. </tr>
  57. </table>
  58. </body>
  59. </html>
  60. """, subtype='html')
  61. # Enviar el correo usando SMTP de Gmail
  62. with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
  63. smtp.login(EMAIL_ORIGEN, CONTRASENA)
  64. smtp.send_message(msg)