Probleme mit smtplib
Verfasst: Donnerstag 1. Februar 2024, 11:26
Hallo Ihr Lieben,
ich möchte mit Python eine E-Mail versenden . Das ist mein Code:
#send email
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
server = smtplib.SMTP('smtp.ionos.de', 465)
try:
name="Mein Name" #You need to fill the name here
server.connect('smtp.ionos.de', 465)
server.starttls()
server.ehlo()
server.login("info@test.de","Passwort")
TOADDR = "test@web.de"
FromADDR = "info@test.de"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Testbetreff"
msg['From'] = FromADDR
msg['To'] = TOADDR
#The below is email body
html = """\
<html>
<body>
<p><span style="color: rgb(0,0,0);">Dear {0},</span></p>
<p>
your email body
</p>
<p>Kind Regards,<br />
Your name ....
</p>
</body>
</html>
""".format(name.split()[0])
msg.attach(MIMEText(html, 'html'))
server.sendmail(FromADDR, TOADDR, msg.as_string())
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()
Ich erhalte folgenden Fehler wenn ich es ausführe:
Traceback (most recent call last):
File "C:\Users\MeinName\Downloads\emailsendenTest3.py", line 5, in <module>
server = smtplib.SMTP('smtp.ionos.de', 465)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 343, in connect
(code, msg) = self.getreply()
^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 405, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Ich verwende Python 3.12
ich möchte mit Python eine E-Mail versenden . Das ist mein Code:
#send email
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
server = smtplib.SMTP('smtp.ionos.de', 465)
try:
name="Mein Name" #You need to fill the name here
server.connect('smtp.ionos.de', 465)
server.starttls()
server.ehlo()
server.login("info@test.de","Passwort")
TOADDR = "test@web.de"
FromADDR = "info@test.de"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Testbetreff"
msg['From'] = FromADDR
msg['To'] = TOADDR
#The below is email body
html = """\
<html>
<body>
<p><span style="color: rgb(0,0,0);">Dear {0},</span></p>
<p>
your email body
</p>
<p>Kind Regards,<br />
Your name ....
</p>
</body>
</html>
""".format(name.split()[0])
msg.attach(MIMEText(html, 'html'))
server.sendmail(FromADDR, TOADDR, msg.as_string())
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()
Ich erhalte folgenden Fehler wenn ich es ausführe:
Traceback (most recent call last):
File "C:\Users\MeinName\Downloads\emailsendenTest3.py", line 5, in <module>
server = smtplib.SMTP('smtp.ionos.de', 465)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 343, in connect
(code, msg) = self.getreply()
^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\smtplib.py", line 405, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Ich verwende Python 3.12