-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvioMail.py
30 lines (27 loc) · 1.11 KB
/
EnvioMail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Configura la información del remitente y destinatario
remitente_email = "[email protected]"
remitente_password = "Asado2023*"
destinatario_email = "[email protected]"
# Configura el servidor SMTP de Outlook
smtp_server = "smtp-mail.outlook.com"
smtp_port = 587
# Construye el mensaje
mensaje = MIMEMultipart()
mensaje["From"] = remitente_email
mensaje["To"] = destinatario_email
mensaje["Subject"] = "Prueba python"
# Añade el cuerpo del mensaje
cuerpo_mensaje = "Hola, este es un ejemplo de envío de correo desde Python a través de Outlook."
mensaje.attach(MIMEText(cuerpo_mensaje, "plain"))
# Inicia la conexión al servidor SMTP
with smtplib.SMTP(smtp_server, smtp_port) as server:
# Establece una conexión segura
server.starttls()
# Inicia sesión en la cuenta de correo
server.login(remitente_email, remitente_password)
# Envía el correo electrónico
server.sendmail(remitente_email, destinatario_email, mensaje.as_string())
print("Correo enviado con éxito.")