2017-03-07 5 views
1

Hier ist der Code, um die Quelle des Bildes nicht nimmt es einfach alt= im html anzeigt img TagDer Code kann das Bild nicht angezeigt wird in Mail

Bild nicht in der E-Mail angezeigt Alles richtig funktioniert aber Ich konnte kein Bild in Google Mail sehen.

ich das Bild und der Code im selben Ordner

import smtplib 

from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText 

# me == my email address 
# you == recipient's email address 
me = "[email protected]" 
you = "[email protected]" 


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). 
# Create the body of the message (a plain-text and an HTML version). 
text = "Hi!\nHow r you?\nHere is the link you wanted:\nhttps://www.python.org" 
html = """\ 
<html> 
    <head></head> 
    <body> 
    <p>An image that is a link:<br> 
     <a href="https://www.w3schools.com"> 
     <img src="yy.jpg" alt="Go to W3Schools!" width="400" height="100" border="0"> 
    </p> 
    </body> 
</html> 
""" 
# Record the MIME types of both parts - text/plain and text/html. 

part1 = MIMEText(text, 'plain') 
part2 = MIMEText(html, 'html') 

# 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) 


s = smtplib.SMTP('smtp.gmail.com',587) 
s.ehlo() 
s.starttls() 
password=input("Enter your password") 
s.login('[email protected]',password) 
# sendmail function takes 3 arguments: sender's address, recipient's #address 
# and message to send - here it is sent as one string. 
s.sendmail(me, you, msg.as_string()) 
s.quit() 
+0

Hoffe, das hilft! http://stackoverflow.com/questions/920910/sending-multipart-html-emails-which-contain-embedded-images –

Antwort

0

Wenn alles des Codes ist in Ordnung, aber man kann immer noch nicht sehen, das Bild in Ihrer E-Mail, bitte denken Sie daran, dass gehalten habe: Ob eine zeigen, Das Bild wird auch von Ihrem E-Mail-Dienst bestimmt. Einige E-Mail-Dienste verbergen das Bild nur aus Sicherheitsgründen. Sie können versuchen, eine andere E-Mail-Adresse mit einem anderen E-Mail-Dienst zu verwenden. PS: Wenn Sie CSS verwenden möchten, um das Layout Ihres HTML anzupassen, "VERGESSEN SIE ES".