通过Python在密码过期之前发送提醒邮件

时间:2019-02-11 06:58:41

标签: python-3.x

import smtplib
import pandas as pd
import csv
import datetime
from datetime import date, timedelta


csv = pd.read_csv(r'C:\Users\renu.sharma\Desktop\Reults.csv', delimiter=',')


csv['Date of Expiry'] = pd.to_datetime(csv['Date of Expiry'], errors='coerce')
today_date = pd.datetime.today().date()
csv2 =  (csv['Date of Expiry'].dt.date - today_date).astype('timedelta64[D]')
def send_me_email():
        server = smtplib.SMTP('Outlook.Office365.com', 587)
        server.ehlo()
        server.starttls()
        server.ehlo()
        server.login('XXX.XXXXXXX@XXX.com', 'XXXXXXXXXX')
        msg = "Please consider changing your password, it will expire in two days"

        server.sendmail("XXX.XXXXXXX@XXX.com", csv['Email id'], msg)
        server.quit()

上面的代码工作正常, 但是当我尝试使用以下代码遍历文件中的所有用户时:

for k in csv:
    if csv2 <= 2.0:
        csv['Email id'].apply(send_me_email())

我遇到以下错误:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

请让我知道我要去哪里了

0 个答案:

没有答案