我正try 使用Win32库通过Django发送邮箱,但没有应用HTML样式.头部的风格是零星的,身体的风格也是零星的
pythoncom.CoInitialize()
dynamic_link='prueba'
try:
# Obtén todos los ingenieros con sus nombres concatenados
outlook = win32.Dispatch('Outlook.Application')
mail = outlook.CreateItem(0)
# Configurar el remitente
mail.SentOnBehalfOfName = 'example@outlook.com'
mail.To = adminEmail
mail.Subject = 'NUEVA SOLICITUD DE PRUEBAS DE LABORATORIO'
html_body = f"""
<html>
<head>
<style>
body {{
font-family: Arial, sans-serif;
padding: 20px;
}}
h1, p {{
color: #333;
}}
.background-red {{
background-color: red;
}}
#button {{
display: inline-block;
padding: 10px 20px;
background-color: #4CAF50;
color: #fff;
text-decoration: none;
border-radius: 5px;
}}
</style>
</head>
<body class="background-red">
<h1>Solicitud de pruebas de laboratorio</h1>
<p>Nueva solicitud pruebas de laboratorio del usuario {FullName}</p>
<div style="width: 130px; height:130px; background-color:white;">
<p>El usuario {FullName} ha creado una nueva solicitud de pruebas de laboratorio para el cliente {customer} con una fecha requerida para el {require_date}</p>
</div>
<a href="{dynamic_link}" id="button">Ir a la página</a>
</body>
</html>
"""
mail.HTMLBody = html_body
mail.Send()
return Response({"message": "Correo enviado correctamente"}, status=status.HTTP_200_OK)
except Exception as e:
print(f"Error: {e}")
finally:
# Liberar recursos
pythoncom.CoUninitialize()