无法通过 smtp 登录或发送电子邮件,也无法使用 (aol) 域的 python 脚本通过 imap 阅读邮件

问题描述 投票:0回答:1

我尝试过多种类型的Python脚本,但主要问题是,创建会话后无法登录。即使我的密码和电子邮件ID是正确的。我尝试了很多方法,请任何人提到我做错了什么。 aol 邮件不鼓励通过 python 脚本使用 imap 和 smtp 吗?或者我还缺少其他什么东西吗?

这是我的 imap 代码,用于登录和阅读 aol.com 的邮件

`imap_ssl = imaplib.IMAP4_SSL(
                    host='imap.aol.com', port=993)
print(
    f"Login to  {'[email protected]'}  for REPLY_FLOW")
resp_code, response = imap_ssl.login(
    '[email protected]','my_password')

print("{} got logged in successfully...".format(
    "[email protected]"))`

这是我每次都会遇到的错误

`examples/yahoo_testing.py"
Login to  [email protected]  for REPLY_FLOW
Traceback (most recent call last):
  File "examples/yahoo_testing.py", line 264, in <module>
    resp_code, response = imap_ssl.login(
  File "/usr/lib/python3.10/imaplib.py", line 612, in login
    raise self.error(dat[-1])
imaplib.IMAP4.error: b'[AUTHENTICATIONFAILED] LOGIN Invalid credentials'`

这是 aol.com 的 smtp 代码

`import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
addr_to   = '[email protected]'
addr_from = 'Me <[email protected]>'
smtp_server = 'smtp.aol.com'
smtp_user   = '[email protected]'
smtp_pass   = 'my_password'
msg = MIMEMultipart('alternative')
msg['To'] = addr_to
msg['From'] = addr_from
msg['Subject'] = 'Email subject'
text = "Plain text goes here"
html = """\
HTML version goes here.
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = smtplib.SMTP_SSL(smtp_server)
s.login(smtp_user,smtp_pass)
s.sendmail(addr_from, addr_to, msg.as_string())
s.quit()`

错误获取是

`Traceback (most recent call last):
File " examples/checking_aol.py", line 42, in <module>
s.login(smtp_user,smtp_pass)
File "/usr/lib/python3.10/smtplib.py", line 739, in login
>!     (code, resp) = self.auth(
File "/usr/lib/python3.10/smtplib.py", line 642, in auth
>!     (code, resp) = self.docmd("AUTH", mechanism + " " + response)
File "/usr/lib/python3.10/smtplib.py", line 432, in docmd
return self.getreply()
File "/usr/lib/python3.10/smtplib.py", line 405, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed`

除了这个脚本之外,我还尝试了其他一些脚本,但没有一个能够让我使用 aol 邮件登录。除了 aol 邮件之外,其他邮件(如 Outlook、gmail 和 Thunderbird)我都可以进入,但仅此我面临问题。任何帮助将不胜感激。

python python-3.x smtp imap aol
1个回答
0
投票

我相信 AOL 以与 Google 相同的方式实现身份验证(即应用程序密码)。

您应该登录 AOL 网站并查找 Imap 设置并生成一个应用程序密码,用于通过 Python 脚本访问收件箱。

此外,您应该使用环境变量,在应用程序中将纯密码存储为可读字符串是不好的。

© www.soinside.com 2019 - 2024. All rights reserved.