【发布时间】:2021-02-16 09:13:09
【问题描述】:
我尝试使用电子邮件提供程序“web.de”通过 python 发送电子邮件。
我在电子邮件服务提供商的设置中激活了电子邮件协议。
出现以下错误消息:
(554, b'Transaction failed\nUnauthorized sender address.')
应该可以这样做,因为我的电子邮件程序可以发送电子邮件。
import smtplib, ssl
smtp_server = "smtp.web.de"
port = 587 # For starttls
sender_email = "someemail@web.de"
password = input("Type your password and press enter: ")
receiver_email = "another@web.de"
message = "Subject: Hi there\n\nThis message is sent from Python."
# Create a secure SSL context
context = ssl.create_default_context()
# Try to log in to server and send email
try:
server = smtplib.SMTP(smtp_server,port)
server.ehlo() # Can be omitted
server.starttls(context=context) # Secure the connection
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
except Exception as e:
# Print any error messages to stdout
print(e)
finally:
server.quit()
【问题讨论】: