我对编程完全陌生,我正在尝试构建一个自动响应器来向特定的电子邮件地址发送消息。
使用 if 语句,我可以检查收件箱中是否有来自某个地址的电子邮件,并且我可以发送电子邮件,但是如果该地址有多个电子邮件,我如何制作 for 循环来为每个电子邮件发送电子邮件来自该特定地址的电子邮件。
我尝试将其用作循环:
for M.search(None, 'From', address) in M.select():
Run Code Online (Sandbox Code Playgroud)
但我在该行收到错误:“无法分配给函数调用”
我正在寻找简单的方法将IMAP响应中出现的括号列表拆分为Python列表或元组.我想要离开
'(BODYSTRUCTURE ("text" "plain" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 1207 50 NIL NIL NIL NIL))'
Run Code Online (Sandbox Code Playgroud)
至
(BODYSTRUCTURE, ("text", "plain", ("charset", "ISO-8859-1"), None, None, "quoted-printable", 1207, 50, None, None, None, None))
Run Code Online (Sandbox Code Playgroud) Subject: Re:
=?UTF-8?Q?Th=E1=BA=A7y_g=E1=BB=ADi_b=C3=A0i_t=E1=BA=ADp_cho_em_v=E1=BB?=
=?UTF-8?Q?=9Bi.?=
Run Code Online (Sandbox Code Playgroud)
我收到了一封有此主题标题的电子邮件.怎么解码?
我正在尝试使用python的imaplib搜索和过滤我的imap邮件.我在搜索命令中遇到了一个非常奇怪的问题,在该FROM字段中搜索电子邮件地址.我有以下脚本,
print('search with name')
status, results = con.search(None, '(FROM "Shrikant Sharat")')
if status == 'OK':
if results[0]:
mid = results[0].split()[0]
print('mail id', mid)
print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
else:
print('No results yielded')
else:
print('unable to search', results)
print()
print('search with email')
status, results = con.search(None, '(FROM "shrikantsharat.k@gmail.com")')
if status == 'OK':
if results[0]:
mid = results[0].split()[0]
print('mail id', mid)
print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])'))
else:
print('No results yielded')
else:
print('unable to search', results)
Run Code Online (Sandbox Code Playgroud)
为此,我得到以下结果,
search with name
mail id 2155 …Run Code Online (Sandbox Code Playgroud) 如何使用IMAP访问查找GMail帐户中包含附件的所有电子邮件?我在使用Python但是只有这样做是检查每条消息吗?
谢谢
我注意到我的IMAP服务器似乎支持IDLE,但通知迟到了.所以我问自己:我如何检查IDLE是否有效(或者是我的邮件客户端)?
python 3中的以下代码在我的计算机上引发错误,我不知道如何正确登录:
import smtplib
connection = smtplib.SMTP('smtp-mail.outlook.com', 587)
connection.ehlo()
connection.starttls()
connection.ehlo()
connection.login('_these_dont_matter@outlook.com', '_the_error_persists_')
Run Code Online (Sandbox Code Playgroud)
最后一行产生以下输出:
Traceback (most recent call last):
File "/usr/lib/python3.3/smtplib.py", line 366, in getreply
line = self.file.readline()
File "/usr/lib/python3.3/socket.py", line 297, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.3/ssl.py", line 460, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.3/ssl.py", line 334, in read
v = self._sslobj.read(len, buffer)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1504)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, …Run Code Online (Sandbox Code Playgroud) 我正在使用Python imaplib.IMAP4连接到Google电子邮件.除非我使用IMAP4.select()包含空格字符的邮箱名称的方法,否则每件事都可以.假设我的邮箱名称是"Gama Sutra".
当我执行imap.select('[Gmail]/Gama Sutra')它时给我这个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 682, in select
typ, dat = self._simple_command(name, mailbox)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 1133, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 964, in _command_complete
raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SELECT command error: BAD [b'Could not parse command']
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
代码:标题中出现错误,但我在这里没有看到问题
def test():
imap_host = 'imap.gmail.com'
imap_user = 'email'
imap_pass = 'pass'
imap = imaplib.IMAP4_SSL(imap_host)
imap.login(imap_user, imap_pass)
imap.select('"[Gmail]/All Mail"')
message = imap.search(None, 'SUBJECT', "Verify your email")
print(message)
test()
Run Code Online (Sandbox Code Playgroud)
这里有什么问题吗?