0
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()

The above code is working fine, but when i am trying to loop through all the users in the file with the below code:

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

i am getting the following Error :

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

Please let me know where i am going wrong

  • `csv2`, like `csv` is a [dictionary](https://www.tutorialspoint.com/python/python_dictionary.htm), so you cannot compare it to a number. You can loop through its contents like [this](https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops), or compare directly with `csv['Date of Expiry']` – hyperTrashPanda Feb 11 '19 at 07:01
  • Thanks for your reply, but i am not very well acquainted with Python, can you please explain the loop thing, – Renu sharma Feb 11 '19 at 08:19

0 Answers0