47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from datetime import datetime
|
|
|
|
# Configuración del servidor SMTP (Sin SSL)
|
|
SMTP_SERVER = "192.168.120.103"
|
|
SMTP_PORT = 25 # También puedes probar 587 si 25 no funciona
|
|
EMAIL_USER = "pruebas@psp.ieslamar.org"
|
|
EMAIL_PASS = "1234"
|
|
|
|
def enviar_correo(destinatario, asunto, mensaje):
|
|
try:
|
|
# Obtener la fecha y hora actual
|
|
fecha_envio = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
# Crear mensaje con la fecha incluida
|
|
msg = MIMEMultipart()
|
|
msg["From"] = EMAIL_USER
|
|
msg["To"] = destinatario
|
|
msg["Subject"] = asunto
|
|
msg["Date"] = fecha_envio # Agregar la fecha en la cabecera del correo
|
|
|
|
# Formato del mensaje con la fecha en el cuerpo
|
|
mensaje_completo = f"""
|
|
asdasdsad
|
|
|
|
{mensaje}
|
|
"""
|
|
|
|
msg.attach(MIMEText(mensaje_completo, "plain")) # Mensaje en texto plano
|
|
|
|
# Conectar al servidor SMTP SIN SSL
|
|
server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
server.ehlo()
|
|
server.login(EMAIL_USER, EMAIL_PASS) # Iniciar sesión
|
|
server.sendmail(EMAIL_USER, destinatario, msg.as_string())
|
|
server.quit()
|
|
|
|
print(f"Correo enviado a {destinatario} el {fecha_envio}")
|
|
|
|
except Exception as e:
|
|
print(f"Error enviando correo: {e}")
|
|
|
|
# Uso del script
|
|
enviar_correo("kevin@psp.ieslamar.org", "Prueba de Correo", "Este es un mensaje de prueba sin SSL.")
|