简体   繁体   English

从Bash或Python检查邮件主题

[英]Checking mail subject from Bash or Python

I have many cron jobs running on various servers, I want to check the status of the jobs via mail using command line. 我有许多在各种服务器上运行的cron作业,我想使用命令行通过邮件检查作业的状态。 The only way seems to me is to extract the subject or body of the mail the jobs sent. 在我看来,唯一的方法是提取作业发送的邮件的主题或正文。 cron will send mail regardless of the success or failure. 无论成功与否, cron都会发送邮件。

For example, upon success cron will send a mail with subject: 例如,成功完成后, cron将发送主题为:

Done..succeeded

If failed: 如果失败:

Not done..Failed

The cron jobs run at specific times eg lets take 10:00, 16:00 and 22:30 everyday. cron作业在特定时间运行,例如,每天花费10:00、16:00和22:30。

I have tried curl and urllib2 but could not get desired result. 我已经尝试过curlurllib2但是无法获得想要的结果。 Also note that i can not make any modification to cron itself, the only option is to check the gmail. 另请注意,我无法对cron本身进行任何修改,唯一的选择是检查gmail。

So how can i check my gmail from bash or python to extarct the subject so that i get get an idea of the cron job? 那么,如何才能从bashpython检查我的gmail以突出显示该主题,以便使我对cron工作有所了解?

You can use imaplib to talk to Gmail with the IMAP protocol. 您可以使用imaplib通过IMAP协议与Gmail通讯。 This is the same protocol that you would use to have Gmail work with eg Thunderbird, so it's fairly easy to retrieve messages rather than dealing with scraping often-changing HTML. 这是与Gmail配合使用(例如Thunderbird)时所使用的协议,因此检索邮件而不是处理经常更改的HTML抓取非常容易。

I had some python code that used to check gmail for me. 我有一些用于为我检查gmail的python代码。 I was going to post it but I tried it out and it no longer works for me. 我本来打算发布它,但我尝试了一下,但它不再对我有用。 I haven't used it for about a year and Gmail has updated their auth to use oauth2 which is more secure. 我已经使用了大约一年了,Gmail已将其身份验证更新为使用更安全的oauth2。 You may be able to get imaplib to work as well but you will need to enable less secure apps on your gmail account. 您也许可以使imaplib正常运行,但需要在gmail帐户上启用安全性较低的应用。 If I have time to tweak it and get it working I will post it. 如果我有时间对其进行调整并使它正常工作,我会发布它。 In the meantime this link looks like a pretty good walk-through of how to get it working. 同时,此链接看起来像一个很好的演练,介绍了如何使其工作。 https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 主题行未出现在从python发送的smtp邮件中 - Subject line not coming in the smtp mail sent from python 从python中的函数调用时,邮件传递时没有主题 - mail is delivering without subject when calling from function in python 在 Python 3.x 中解码邮件主题 Thunderbird - Decoding Mail Subject Thunderbird in Python 3.x python:希望从今天收到的 outlook 邮件中保存附件并带有特定主题 - python: looking to save attachments from outlook mail received Today and with specific subject Python邮件在Outlook主题行中放置了无法计算的空间 - Python mail puts unaccounted space in Outlook Subject line 在Python邮件功能中填充其他电子邮件字段,例如“主题” - Populate other email fields like Subject in Python mail function 如何在python中解码编码电子邮件主题行? - How to decode encode e-mail subject line in python? 用于更改 Outlook 邮件项目主题行的 Python 函数 - Python function for changing the subject line of an Outlook mail item 使用非 ASCII 字符将邮件主题 (SMTP) 编码为 Python - Encoding mail subject (SMTP) in Python with non-ASCII characters 尝试在python中使用smtplib发送邮件。 邮件正文与主题行一起出现 - Trying to send a mail using smtplib in python. Mail body comes alongwith subject line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM