list devolverá una lista de correo, que es una lista con tres elementos. El segundo elemento es el número de serie de todos los mensajes.
Por ejemplo: si tiene 10 correos electrónicos en su buzón, entonces la lista es 1-10.
SUGERENCIA: Si eres un programador antiguo, antiguo C o antiguo Python, la primera posición de la lista es 0 y, lamentablemente, el primer número de correo electrónico es 1.
Recibe otro correo electrónico, por lo que el número de serie es 11.
————————————————————————
Puede guardar el número de serie en un archivo y luego sondear regularmente. Cuando este número cambia, significa que hay un nuevo correo.
Usando las funciones OS, open y time, no hablaré de eso. La lógica es demasiado simple.
El comando para obtener el correo es retr (i), donde i es el número de serie del correo, devolverá una lista y el segundo es el cuerpo del correo.
Puede usar print () directamente para ver el código fuente del correo.
Este es el código fuente de un correo electrónico. codificación bytes64.
Received: from Jtjnmail201614.home.langchao.com (10.100.2.14) by
Jtjnmail201618.home.langchao.com (10.100.2.18) with Microsoft SMTP Server
(version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4
via Mailbox Transport; Wed, 3 Feb 2021 11:06:40 +0800
Received: from jtjnmail201609.home.langchao.com (10.100.2.9) by
Jtjnmail201614.home.langchao.com (10.100.2.14) with Microsoft SMTP Server
(version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
15.1.2044.4; Wed, 3 Feb 2021 11:06:40 +0800
Received: from mailgate.inspur.com (172.30.26.49) by
jtjnmail201609.home.langchao.com (10.100.2.9) with Microsoft SMTP Server id
15.1.2044.4; Wed, 3 Feb 2021 11:06:40 +0800
Received: from globalnet19.corpsmtp.net (unknown [222.73.239.19])
(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by Forcepoint Email with ESMTPS id AC218AD871CBD317F703
for <[email protected]>; Wed, 3 Feb 2021 11:02:48 +0800 (CST)
Received: from cmccmta1.chinamobile.com ([221.176.66.79])
by globalnet19.corpsmtp.net ([EK]) with ESMTP id EK202102031106369519
for <[email protected]>; Wed, 03 Feb 2021 11:06:36 +0800
Received: from spf.mail.chinamobile.com (unknown[172.16.121.13]) by rmmx-syy-dmz-app04-12004 (RichMail) with SMTP id 2ee4601a133b96d-a4cd0; Wed, 03 Feb 2021 11:06:35 +0800 (CST)
X-RM-TRANSID: 2ee4601a133b96d-a4cd0
X-RM-TagInfo: emlType=0
X-RM-SPAM-FLAG: 00000000
Received: from DY-WL-JIANKONG3 (unknown[10.18.75.220])
by rmsmtp-syy-appsvr07-12007 (RichMail) with SMTP id 2ee7601a133ac25-517c6;
Wed, 03 Feb 2021 11:06:35 +0800 (CST)
X-RM-TRANSID: 2ee7601a133ac25-517c6
Sender: <[email protected]>
x-PcFlag: e4277e7e-5c62-4809-92b0-70e499004780_23_12367
X-Mailer: PC_RICHMAIL 2.8.2
Date: Wed, 3 Feb 2021 11:06:39 +0800
From: dyjkz <[email protected]>
To: sdmcceoms <[email protected]>
CC:
Subject: =?utf-8?B?5Lic6JCl5ZGK6K2m5rWB5rC05Y+35ZCK5q2777yM54Om6K+35Y2P5Yqp5aSE55CG77yM6LCi6LCi77yB?=
Message-ID: [email protected]>
Content-Type: multipart/alternative;
boundary="----=_001_NextPart-1498277105_=----"
TSender: [email protected]
tRcpt: <[email protected]>;
tUid: G20210203110636551ac1ce4fcfb28c9c61f785938e74da
Tcorpfrom: [email protected]
tIPaddress: 221.176.66.79
Return-Path: [email protected]
X-MS-Exchange-Organization-Network-Message-Id: dbd21430-a9c2-4bce-33e9-08d8c7f0ba3a
X-MS-Exchange-Organization-AVStamp-Enterprise: 1.0
X-MS-Exchange-Organization-AuthSource: jtjnmail201609.home.langchao.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Transport-EndToEndLatency: 00:00:00.3962161
X-MS-Exchange-Processed-By-BccFoldering: 15.01.2044.007
MIME-Version: 1.0
------=_001_NextPart-1498277105_=----
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
DQ0NDQ0NDea1qua9ruaCqOWlve+8jOS4nOiQpeWRiuitpua1geawtOWPtzogICAxMTI4NjA1Nzkx
ICDvvIzlkIrmrbvvvIzng6bor7fljY/liqnlpITnkIbvvIzosKLosKLvvIENDQ0NDQ0N
------=_001_NextPart-1498277105_=----
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<html><head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"><s=
tyle>div {
font-size: 12pt; color: #000000; font-family:=E5=BE=AE=E8=BD=AF=
=E9=9B=85=E9=BB=91;}</style></head><body style=3D"word-wrap: break-word; -w=
ebkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div style=
=3D"word-wrap: break-word;"><div style=3D"color: rgb(0, 0, 0); font-family:=
=E5=BE=AE=E8=BD=AF=E9=9B=85=E9=BB=91; font-size: 12pt; word-wrap: break-wo=
rd;"><br></div><div style=3D"word-wrap: break-word;"><span style=3D"font-si=
ze: 12pt; line-height: 24px;">=E6=B5=AA=E6=BD=AE=E6=82=A8=E5=A5=BD=EF=BC=8C=
=E4=B8=9C=E8=90=A5=E5=91=8A=E8=AD=A6=E6=B5=81=E6=B0=B4=E5=8F=B7:</span><spa=
n style=3D"font-size: 12pt; line-height: 24px;"> </span>1128605=
791 <span style=3D"font-size: 12pt;">=EF=BC=8C</span><span style=3D"f=
ont-size: 12pt; line-height: 24px;">=E5=90=8A=E6=AD=BB=EF=BC=8C=E7=83=A6=E8=
=AF=B7=E5=8D=8F=E5=8A=A9=E5=A4=84=E7=90=86=EF=BC=8C=E8=B0=A2=E8=B0=A2=EF=BC=
=81</span></div><div style=3D"color: rgb(0, 0, 0); font-family: =E5=BE=AE=
=E8=BD=AF=E9=9B=85=E9=BB=91; font-size: 12pt; word-wrap: break-word;"><br><=
/div></div><div id=3D"SIGNNAME12367"></div><div><span id=3D"_THINKMAILNAME1=
2367" font-size:12pt;font-family:microsoftyahei;=3D""></span></div></body><=
/html>
------=_001_NextPart-1498277105_=------
Medio hecho con éxito.
El correo incluye el encabezado y el cuerpo del correo. El encabezado del mensaje incluye la información del remitente, la información del destinatario, la hora de envío, CC, etc.
Date: Wed, 3 Feb 2021 11:06:39 +0800
From: dyjkz <[email protected]>
To: sdmcceoms <[email protected]>
CC:
Subject: =?utf-8?B?5Lic6JCl5ZGK6K2m5rWB5rC05Y+35ZCK5q2777yM54Om6K+35Y2P5Yqp5aSE55CG77yM6LCi6LCi77yB?=
Message-ID: [email protected]>
Content-Type: multipart/alternative;
Equivalente al
cuerpo del correo.
El cuerpo del correo incluye información como archivos y textos. Si solo desea obtener información de texto, puede buscar directamente
texto / html y texto / sin formato
Por ejemplo, el texto de este correo electrónico es
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
DQ0NDQ0NDea1qua9ruaCqOWlve+8jOS4nOiQpeWRiuitpua1geawtOWPtzogICAxMTI4NjA1Nzkx
ICDvvIzlkIrmrbvvvIzng6bor7fljY/liqnlpITnkIbvvIzosKLosKLvvIENDQ0NDQ0N
Debido a que es base64, pero el juego de caracteres es utf-8
, es muy simple: obtenga el juego de caracteres y luego transcodifique en el texto correspondiente, puede leer correctamente la información del texto del correo electrónico.