首页 > 解决方案 > 如果收到电子邮件,如何在 Python 中做某​​事?

问题描述

我正在用 Python 创建一个脚本,每次收到电子邮件时都会打开我的 Phillips Hue 灯。

我希望我的脚本每 60 秒检查一次电子邮件。我一直无法找到任何好方法来做类似的事情,if received email, then. 所有其他方式似乎也试图解码消息。

我有的代码:

lights = accessing_lights(bridge_ip_var)
while True:
    time.sleep(60)
    # This would be where there would be some sort of if statement to check if there was an email or not 

    for light in lights:
        lights[light].on = True
        lights[light].hue = 7000
        lights[light].saturation = 100


    time.sleep(3)

    for light in lights:
        lights[light].on = False

我已经参与过项目,smtplib因此使用它是理想的。

标签: pythonemailgmailsmtplibphilips-hue

解决方案


推荐阅读