如果使用Python满足条件,则触发电子邮件

时间:2018-05-09 10:41:13

标签: python-3.x

如果条件为true,我试图触发电子邮件。下面是我正在使用的脚本的一部分。虽然它不会抛出任何错误,但在满足第一个条件时也不会触发电子邮件。

....if text>content1:
    o365_auth = ('susername.com.com', 'pwd')
    m = Message(auth=o365_auth)
    m.setRecipients('username.com','ausername.com.com')
    m.setSubject('Data found.')
    m.setBody('New Data found.')
    m.sendMessage()
elif text==content1:
    print("NO Data found for today.")
else:
    print("Process Complete")

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

突出显示的微小调整解决了该问题。不允许使用多个收件人。

 ....if text>content1:
        o365_auth = ('susername.com.com', 'pwd')
        m = Message(auth=o365_auth)
        receipts = ['username.com', 'ausername.com.com']# Build a list of recepients and used the same in below code.
        #m.setRecipients('username.com','ausername.com.com') # Removed this piece
        m.setRecipients(receipts) 
        m.setSubject('Data found.')
        m.setBody('New Data found.')
        m.sendMessage()
    elif text==content1:
        print("NO Data found for today.")
    else:
        print("Process Complete")