smtplib: Versandproblem mit Python3, funktioniert mit Py2.5
Verfasst: Mittwoch 8. April 2009, 13:34
Hi Python-Forum,
ich bin neu hier und mir nicht ganz sicher, ob ich mit der Frage im richtigen Forum gelandet bin...
Folgender Code funktioniert unter Python2.5 ohne Probleme.
Bei Python 3 bekomme ich allerdings sehr seltsame Fehlermeldungen.
Bei Python 2.5 wird die E-Mail ohne weiteres versendet, bei Python 3 bekomme ich folgende Meldung (auf der interaktiven Konsole eingegeben):
Wäre nett, wenn jemand mit Rat und Tat helfen könnte, vielen Dank schon einmal im Voraus .
Edit: Ich weiß, dass ihr gerne simplemail benutzt, damit habe ich es noch nicht probiert. Ich würde das im Moment erst einmal gerne mit der Standard-Lib hinbekommen.
ich bin neu hier und mir nicht ganz sicher, ob ich mit der Frage im richtigen Forum gelandet bin...
Folgender Code funktioniert unter Python2.5 ohne Probleme.
Bei Python 3 bekomme ich allerdings sehr seltsame Fehlermeldungen.
Code: Alles auswählen
import smtplib
from email.message import Message
absender = "absender@host.tld"
empfaenger = "empfaenger@host.tld"
pw = "MeinPasswort"
msg = Message()
msg.set_payload("Test")
msg["Subject"] = "betreff"
msg["From"] = absender
msg["To"] = empfaenger
smtp = smtplib.SMTP("host.tld")
smtp.set_debuglevel(1)
# starttls() macht keinen Unterschied
# smtp.starttls()
smtp.login(msg["From"], pw)
smtp.sendmail(msg["From"], msg["To"], msg.as_string())
gebe ich jetzt allerdings noch einmal die gleiche Zeile ein, bekomme ich eine andere Meldung:>>> smtp.sendmail(msg["From"], msg["To"], msg.as_string())
send: 'mail FROM:<absender@host.tld> size=62\r\n'
reply: b'500 5.5.2 Error: bad syntax\r\n'
reply: retcode (500); Msg: b'5.5.2 Error: bad syntax'
send: 'rset\r\n'
reply: b'250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: b'2.1.0 Ok'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.0/smtplib.py", line 701, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (500, b'5.5.2 Error: bad syntax', 'absender@host.tld')
Es wird also eine Exception geworfen, obwohl der AntwortCode 250, also alles ok, vom Mailserver kommt.>>> smtp.sendmail(msg["From"], msg["To"], msg.as_string())
send: 'mail FROM:<absender@host.tld> size=62\r\n'
reply: b'250 2.0.0 Ok\r\n'
reply: retcode (250); Msg: b'2.0.0 Ok'
send: 'rcpt TO:<empfaenger@host.tld>\r\n'
reply: b'250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: b'2.1.0 Ok'
send: 'data\r\n'
reply: b'250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: b'2.1.5 Ok'
data: (250, b'2.1.5 Ok')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.0/smtplib.py", line 713, in sendmail
(code,resp) = self.data(msg)
File "/usr/lib/python3.0/smtplib.py", line 475, in data
raise SMTPDataError(code,repl)
smtplib.SMTPDataError: (250, b'2.1.5 Ok')
Wäre nett, wenn jemand mit Rat und Tat helfen könnte, vielen Dank schon einmal im Voraus .
Edit: Ich weiß, dass ihr gerne simplemail benutzt, damit habe ich es noch nicht probiert. Ich würde das im Moment erst einmal gerne mit der Standard-Lib hinbekommen.