Limitar archivos a 1
This commit is contained in:
parent
877c95cead
commit
32abb88fae
Binary file not shown.
Binary file not shown.
Binary file not shown.
18
modelo.py
18
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-.]+$"
|
||||
|
|
12
vista.py
12
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()
|
||||
|
|
Loading…
Reference in New Issue