Python - Enviar contenido html por correo

 
Vista:
Imágen de perfil de Victor
Val: 2
Ha disminuido su posición en 19 puestos en Python (en relación al último mes)
Gráfica de Python

Enviar contenido html por correo

Publicado por Victor (4 intervenciones) el 11/10/2019 16:14:02
Como estan mis amigos/as, les estoy molestando para una consulta sobre un tema que estoy tratando de resolver y por favor necesito de la ayuda de esta grandiosa comunidad de informáticos. Mi problema es lo siguiente, estoy tratando de enviar el contenido de un html que contiene una imagen pero al abrir el correo enviado no se ve la imagen, para corroborar si esta todo bien mi contenido de html lo probe en un navegador y esta todo en orden muestra bien la imagen pero al enviar desde mi aplicación y abrir en mi correo no es lo mismo.. abajo les pase el codigo y subi una imagen para que puedan ver el problema. Cualquier comentario es bienvenido desde ya muchas gracias.
Saludos cordiales :)

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import smtplib
 
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
 
# me == my email address
# you == recipient's email address
me    = "informatica@dominio.com.py"
you   = "direccion_correo.czu@gmail.com"
login = 'radsadfdsasd'

# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you

# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"

html = """\
<head>
<meta charset="utf-8" />
<title>sin título</title>
</head>

<body>
  <body>
    <img src = "C:\\Users\\MiTierra\\Desktop\\screenshot.png"  width="350" height="400">
    <p>Hi!<br>
       How are you?<br>
       Here is the <a href="http://www.python.org">link</a> you wanted.
    </p>
</html>
</body>

</html>
"""
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
part3 = MIMEText(html, 'html', 'utf-8')

# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
msg.attach(part3)
# Send the message via local SMTP server.
mail = smtplib.SMTP('smtp-mail.outlook.com:587')

mail.ehlo()

mail.starttls()

mail.login(me, login)
mail.sendmail(me, you, msg.as_string())
mail.quit()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder