diff --git a/__pycache__/controlador.cpython-313.pyc b/__pycache__/controlador.cpython-313.pyc index b21b685..2ac4385 100644 Binary files a/__pycache__/controlador.cpython-313.pyc and b/__pycache__/controlador.cpython-313.pyc differ diff --git a/__pycache__/modelo.cpython-313.pyc b/__pycache__/modelo.cpython-313.pyc index 20fd2c9..6e3cda6 100644 Binary files a/__pycache__/modelo.cpython-313.pyc and b/__pycache__/modelo.cpython-313.pyc differ diff --git a/__pycache__/vista.cpython-313.pyc b/__pycache__/vista.cpython-313.pyc index b7f8ca2..517684d 100644 Binary files a/__pycache__/vista.cpython-313.pyc and b/__pycache__/vista.cpython-313.pyc differ diff --git a/modelo.py b/modelo.py index 7425b2f..79b8e29 100644 --- a/modelo.py +++ b/modelo.py @@ -123,6 +123,9 @@ class CorreoModelo: try: if not CorreoModelo.validar_correo(destinatario): return False, "Dirección de correo inválida" + + if len(archivos_adjuntos) > 1: + return False, "Solo se permite un archivo adjunto" fecha_envio = datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -132,20 +135,17 @@ class CorreoModelo: msg["Subject"] = asunto msg["Date"] = fecha_envio - mensaje_completo = f"{mensaje}" - msg.attach(MIMEText(mensaje_completo, "plain")) + msg.attach(MIMEText(mensaje, "plain")) - # Agregar archivos adjuntos - for archivo in archivos_adjuntos: + # Adjuntar el único archivo permitido + if archivos_adjuntos: + archivo = archivos_adjuntos[0] if os.path.exists(archivo): with open(archivo, "rb") as adjunto: part = MIMEBase("application", "octet-stream") part.set_payload(adjunto.read()) encoders.encode_base64(part) - part.add_header( - "Content-Disposition", - f"attachment; filename={os.path.basename(archivo)}", - ) + part.add_header("Content-Disposition", f"attachment; filename={os.path.basename(archivo)}") msg.attach(part) server = smtplib.SMTP(CorreoModelo.SMTP_SERVER, CorreoModelo.SMTP_PORT) @@ -158,7 +158,7 @@ class CorreoModelo: except Exception as e: return False, f"Error enviando correo: {e}" - + @staticmethod def validar_correo(destinatario): patron = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" diff --git a/vista.py b/vista.py index 08f2fb1..60daeb4 100644 --- a/vista.py +++ b/vista.py @@ -140,13 +140,13 @@ class CorreoVista: btn_enviar.pack(pady=10) def seleccionar_archivos(self): - archivos = filedialog.askopenfilenames(title="Seleccionar archivos adjuntos") - if archivos: - self.archivos_adjuntos = list(archivos) - archivos_texto = "\n".join(self.archivos_adjuntos) - self.label_archivos.config(text=f"Archivos adjuntos:\n{archivos_texto}") + archivo = filedialog.askopenfilename(title="Seleccionar un archivo adjunto") # Permitir solo un archivo + if archivo: + self.archivos_adjuntos = [archivo] # Solo un archivo en la lista + self.label_archivos.config(text=f"Archivo adjunto: {archivo}") else: - self.label_archivos.config(text="No hay archivos adjuntos") + self.label_archivos.config(text="No hay archivo adjunto") + def enviar_correo(self): destinatario = self.entry_destinatario.get().strip()