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:
|
try:
|
||||||
if not CorreoModelo.validar_correo(destinatario):
|
if not CorreoModelo.validar_correo(destinatario):
|
||||||
return False, "Dirección de correo inválida"
|
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")
|
fecha_envio = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
@ -132,20 +135,17 @@ class CorreoModelo:
|
||||||
msg["Subject"] = asunto
|
msg["Subject"] = asunto
|
||||||
msg["Date"] = fecha_envio
|
msg["Date"] = fecha_envio
|
||||||
|
|
||||||
mensaje_completo = f"{mensaje}"
|
msg.attach(MIMEText(mensaje, "plain"))
|
||||||
msg.attach(MIMEText(mensaje_completo, "plain"))
|
|
||||||
|
|
||||||
# Agregar archivos adjuntos
|
# Adjuntar el único archivo permitido
|
||||||
for archivo in archivos_adjuntos:
|
if archivos_adjuntos:
|
||||||
|
archivo = archivos_adjuntos[0]
|
||||||
if os.path.exists(archivo):
|
if os.path.exists(archivo):
|
||||||
with open(archivo, "rb") as adjunto:
|
with open(archivo, "rb") as adjunto:
|
||||||
part = MIMEBase("application", "octet-stream")
|
part = MIMEBase("application", "octet-stream")
|
||||||
part.set_payload(adjunto.read())
|
part.set_payload(adjunto.read())
|
||||||
encoders.encode_base64(part)
|
encoders.encode_base64(part)
|
||||||
part.add_header(
|
part.add_header("Content-Disposition", f"attachment; filename={os.path.basename(archivo)}")
|
||||||
"Content-Disposition",
|
|
||||||
f"attachment; filename={os.path.basename(archivo)}",
|
|
||||||
)
|
|
||||||
msg.attach(part)
|
msg.attach(part)
|
||||||
|
|
||||||
server = smtplib.SMTP(CorreoModelo.SMTP_SERVER, CorreoModelo.SMTP_PORT)
|
server = smtplib.SMTP(CorreoModelo.SMTP_SERVER, CorreoModelo.SMTP_PORT)
|
||||||
|
@ -158,7 +158,7 @@ class CorreoModelo:
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False, f"Error enviando correo: {e}"
|
return False, f"Error enviando correo: {e}"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validar_correo(destinatario):
|
def validar_correo(destinatario):
|
||||||
patron = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"
|
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)
|
btn_enviar.pack(pady=10)
|
||||||
|
|
||||||
def seleccionar_archivos(self):
|
def seleccionar_archivos(self):
|
||||||
archivos = filedialog.askopenfilenames(title="Seleccionar archivos adjuntos")
|
archivo = filedialog.askopenfilename(title="Seleccionar un archivo adjunto") # Permitir solo un archivo
|
||||||
if archivos:
|
if archivo:
|
||||||
self.archivos_adjuntos = list(archivos)
|
self.archivos_adjuntos = [archivo] # Solo un archivo en la lista
|
||||||
archivos_texto = "\n".join(self.archivos_adjuntos)
|
self.label_archivos.config(text=f"Archivo adjunto: {archivo}")
|
||||||
self.label_archivos.config(text=f"Archivos adjuntos:\n{archivos_texto}")
|
|
||||||
else:
|
else:
|
||||||
self.label_archivos.config(text="No hay archivos adjuntos")
|
self.label_archivos.config(text="No hay archivo adjunto")
|
||||||
|
|
||||||
|
|
||||||
def enviar_correo(self):
|
def enviar_correo(self):
|
||||||
destinatario = self.entry_destinatario.get().strip()
|
destinatario = self.entry_destinatario.get().strip()
|
||||||
|
|
Loading…
Reference in New Issue