- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章python 自动监控最新邮件并读取的操作由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
我就废话不多说了,大家还是直接看代码吧~ 。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#zmail库:可以用几行代码帮我们收取一封邮件
import
zmail
#输入账号和密码
server
=
zmail.server(
'13163964546@qq.com'
,
'jie110341'
)
#获取最新的一封邮件
mail
=
server.get_latest()
#读取邮件
#zmail.show(mail)
#读取邮件的部分内容
print
(mail[
'subject'
])
......
#读取附件 邮件 存放路径 如果有同名文件则覆盖
zmail.save_acctachment(mail,target_path
=
None
,overwrite
=
True
)
|
需要在电脑上下载zmail库 。
补充:Python邮箱实施监控电脑 。
我就废话不多说了,大家还是直接看代码吧~ 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import
smtplib
import
poplib
import
email
from
email.mime.application
import
MIMEApplication
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
email.header
import
decode_header
def
send_email(account, password, email_title, send_text
=
"
", file_names=None, file_dir="
."):
msg
=
MIMEMultipart()
# msg = MIMEText(HTML, 'html') -- 只能发送文本内容
content
=
MIMEText(send_text,
"plain"
,
"utf-8"
)
msg.attach(content)
# 文件类型
if
isinstance
(file_names,
list
):
for
file_name
in
file_names:
send_file_path
=
file_dir
+
"/"
+
file_name
part
=
MIMEApplication(
open
(send_file_path,
'rb'
).read())
part.add_header(
'Content-Disposition'
,
'attachment'
, filename
=
file_name)
msg.attach(part)
elif
isinstance
(file_names,
str
):
send_file_path
=
file_dir
+
"/"
+
file_names
part
=
MIMEApplication(
open
(send_file_path,
'rb'
).read())
part.add_header(
'Content-Disposition'
,
'attachment'
, filename
=
file_names)
msg.attach(part)
# msg['from'],msg['to']接收端显示的发件人与收件人
msg[
'from'
]
=
"奥巴马@163.com"
msg[
'to'
]
=
account
msg[
'subject'
]
=
email_title
try
:
server
=
smtplib.SMTP()
server.connect(
'smtp.163.com'
)
server.login(account, password)
# from_addr:发送地址; to_addrs:接收地址(字符串列表)
server.sendmail(account, msg[
'to'
].split(), msg.as_string())
except
Exception as e:
print
(e)
# 获取邮件标题
def
get_email_subject(addr, password):
# 设置连接网址,获取pop3协议的邮件读取对象
read
=
poplib.POP3(
'pop.163.com'
, timeout
=
3600
)
# 输入邮件地址与邮件登录密码
read.user(addr)
# 163邮箱用户名
read.pass_(password)
# 163邮箱设置中的客户端授权密码
# allEmails = (totalNum, totalSize)
# 读取邮件信息(邮件总数,邮件尺寸)
total_num, total_size
=
read.stat()
# top(which,howmuch)
# 获取最新的一封邮件(第几封邮件,获取多少封)
top_email
=
read.top(total_num,
1
)
# print("***** start *****\n接收的数据为: {}\n***** end *****\n".format(top_email))
#
# print("***** start *****\n[解码前]获取的初始邮件内容: {}\n***** end *****\n".format(top_email[1]))
# 解码邮件信息,将解码后的邮件信息存入tmp
tmp
=
[]
for
s
in
top_email[
1
]:
tmp.append(s.decode())
# print("***** start *****\n[解码后]的邮件内容为: {}\n***** end *****\n".format(tmp))
# 将解码后的邮件内容拼接为字符串
email_str
=
'\n'
.join(tmp)
# 将字符串类型解析为Message类型
message
=
email.message_from_string(email_str)
# print("***** start *****\n"
# "[解码前]的邮件字符串内容为: [数据类型]{}\n{}\n"
# "--------------------------------------------\n"
# "[解码后]的邮件字符串内容为: [数据类型]{}\n{}\n"
# "***** end *****\n"
# .format(type(email_str), email_str, type(message), message))
# 获取邮件主题
subject_str
=
message[
'subject'
]
# print("***** start *****\n[解码前]邮件标题: {}\n***** end *****\n".format(subject_str))
subject
=
decode_header(subject_str)
# print("***** start *****\n[解码后]邮件标题: {}\n***** end *****\n".format(subject))
content
=
subject[
0
][
0
]
enc_type
=
subject[
0
][
1
]
if
enc_type:
subject_decode
=
content.decode(enc_type)
else
:
subject_decode
=
content
return
subject_decode, read, total_num
|
以上为个人经验,希望能给大家一个参考,也希望大家多多支持我。如有错误或未考虑完全的地方,望不吝赐教.
原文链接:https://blog.csdn.net/weixin_45554040/article/details/102991398 。
最后此篇关于python 自动监控最新邮件并读取的操作的文章就讲到这里了,如果你想了解更多关于python 自动监控最新邮件并读取的操作的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我已经在 ubuntu 14.0 上成功安装了 Zabbix 3.2 服务器主机上的 Z 是绿色的。不幸的是,JMX 是红色的。 Zabbix 服务器:192.168.1.112 带有 tomcat
我想制作一个仪表板,显示我们的 Azure 服务总线队列的状态,并显示“添加到队列的消息”、“队列长度”和“已处理的消息”等的历史记录。使用 Azure 管理门户,我可以看到,这些统计信息大部分是手动
我的 MYSQL 每天晚上都有事件,但我不太确定发生了什么,因为即使我将其设置得早于其他事件,它仍然在早上运行。 问题是,我如何检查运行事件的历史记录或日志,哪一个晚上锁了,哪一个是跑了没跑? 谢谢
1、监控log文件大小超过10g的server 和db 复制代码代码如下: create procedure db_sendmail_mssqllogsize as&n
本教程讨论如何使用 AspectJ 开源框架监控 Spring 应用程序在方法执行方面的性能。 传统上,监控每个 Java 方法所花费的时间的最简单方法是在方法的开头和结尾包含一些跟踪行: publi
有什么可以帮助 msmq 监控的吗?当消息出现在队列中并且在休假时相同时,我想获得一些事件/监视器。 最佳答案 查看 Windows 管理性能计数器。 如果您查看管理工具并找到“性能计数器”,您将能够
我的 Tomcat 中的一个巨大的 web 应用程序有时会开始使用过多的 DBCP 连接,从而导致问题。 为了进行调查,我想在每个时间点准确地知道什么线程/方法持有池的连接。不需要是实时的,事后分析就
在浏览器的整个页面生命周期中监视 cookie 并在 cookie 更改时触发事件的最佳 JS 或 JQuery 特定方法是什么? 最佳答案 据我所知,不可能将 change (或类似)事件直接绑定(
我想尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个 sleep 周期为 5 秒的循环,我希望看到程序实际上正在 sleep 并且循环
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我一直在尝试使用 erlang:monitor/2 来监视 gen_server。不幸的是,每次我尝试这个时,Erlang shell 都会进入无限循环。 这是我为测试这一点而编写的测试程序。 -mo
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我想使用 编写一个 shell 脚本来监控集群中的消费者滞后 bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect
在 .NET 中,假设 thread A 锁定了一个对象。同时,线程B和线程C被阻塞,等待线程A解锁对象。 现在,线程 A 解锁了对象。接下来将选择哪个线程(B 或 C)?它是如何确定的? 最佳答案
我搜索过这个主题,但发现很少有有用的细节。有了这些细节,我尝试编写一些代码如下。 注意:在将此帖子标记为重复之前,请将此帖子中共享的详细信息与其他帖子进行比较,而不仅仅是按主题。 - (NSArray
目录 1、指标监控 2、常用的监控端点 3、定制EndPoint 4、spring boot admin(可以使用)
我们使用 Prometheus 和 Grafana 来监控我们的 Kafka 集群。 在我们的应用程序中,我们使用 Kafka 流,Kafka 流有可能因异常而停止。我们正在记录事件 setUnCau
我正在建立一个复杂的网络仿真,并试图捕捉一些重要的性能测量。 我在服务器上运行了 mininet,并且我将视频从一个 mininet 主机流式传输到另一个(使用 -nodisp 选项,因为我没有 GU
Jenkins 的 openstack-plugin 使用 openstack4j 与 openstack 云对话。我正在寻找一种方法,我们可以从客户端的角度监控 openstack4j 所做的 ht
我正在处理一项需要监控 Thunderbolt 端口连接变化的要求。 (当连接或断开 Thunderbolt 电缆时)。 我尝试使用 IOServiceMatching(kIOUSBInterface
我是一名优秀的程序员,十分优秀!