-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSendingMail.py
More file actions
31 lines (24 loc) 路 1.01 KB
/
Copy pathSendingMail.py
File metadata and controls
31 lines (24 loc) 路 1.01 KB
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
31
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Configuraci贸n
smtp_server = 'smtp.example.com' # Cambia esto al servidor SMTP que est茅s utilizando
smtp_port = 587 # Puerto para conexi贸n TLS (puede variar seg煤n el proveedor)
sender_email = 'tu_correo@example.com'
sender_password = 'tu_contrase帽a'
receiver_email = 'destinatario@example.com'
subject = 'Asunto del correo'
message = 'Hola, esto es un ejemplo de correo electr贸nico enviado desde Python.'
# Crear objeto de mensaje MIME
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
# Establecer conexi贸n SMTP
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls() # Iniciar conexi贸n TLS
server.login(sender_email, sender_password) # Iniciar sesi贸n
# Enviar correo electr贸nico
server.sendmail(sender_email, receiver_email, msg.as_string())
print("Correo electr贸nico enviado correctamente.")