Getting unauthorized sender address when using SMTPLib Python(使用 SMTPLib Python 时获取未经授权的发件人地址)
问题描述
我编写了一个非常简单的 Python 脚本,用于自动发送电子邮件.这是它的代码:
I have a very simple Python script that I wrote to send out emails automatically. Here is the code for it:
import smtplib
From = "LorenzoTheGabenzo@gmx.com"
To = ["LorenzoTheGabenzo@gmx.com"]
with smtplib.SMTP('smtp.gmx.com', 587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login("LorenzoTheGabenzo@gmx.com", Password)
Subject = "Test"
Body = "TestingTheBesting"
Message = f"{Subject}
{Body}"
smtp.sendmail(From, To, Message)
每当我运行此代码时,我都会收到一个非常奇怪的错误,告诉我此发件人是未经授权的发件人".这是完整的错误
Whenever I run this code I get a very strange error telling me that this sender is an "unauthorized sender". Here is the error in full
File "test.py", line 17, in <module> smtp.sendmail(From, To, Message)
File "C:UsersJamesAppDataLocalProgramsPythonPython37-32libsmtplib.py", line 888, in sendmail888, in sendmail raise SMTPDataError(code, resp)smtplib.SMTPDataError: (554, b'Transaction failed
Unauthorized sender address.')
我已经在 GMX 设置中启用了 SMTP 访问,但我不确定现在还可以做些什么来解决这个问题.
I've already enabled SMTP access in the GMX settings and I'm unsure about what else to do now to fix this issue.
注意:我知道变量密码还没有定义.这是因为我在发布之前故意将其删除,它是在我的原始代码中定义的.
Note: I know that the variable password has not been defined. This is because I intentionally removed it before posting, it's defined in my original code.
推荐答案
GMX 检查邮件标头是否匹配标头中的发件人"条目和实际发件人.您提供了一个简单的字符串作为消息,因此没有标题,因此 GMX 出错.为了解决这个问题,您可以使用电子邮件包中的消息对象.
GMX checks a messages header for a match between the "From" entry in the header and the actual sender. You provided a simple string as message, so there is no header, and hence the error by GMX. In order to fix this, you can use a message object from the email package.
import smtplib
from email.mime.text import MIMEText
Subject = "Test"
Body = "TestingTheBesting"
Message = f"{Subject}
{Body}"
msg = MIMEText(Message)
msg['From'] = "LorenzoTheGabenzo@gmx.com"
msg['To'] = ["LorenzoTheGabenzo@gmx.com"]
with smtplib.SMTP('smtp.gmx.com', 587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login("LorenzoTheGabenzo@gmx.com", Password)
smtp.sendmail(msg['From'], msg['To'], msg)
这篇关于使用 SMTPLib Python 时获取未经授权的发件人地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 SMTPLib Python 时获取未经授权的发件人地址
基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 包装空间模型 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
