This is my first programming project with real world application.  It's purpose is to take a file from a directory, encrypt it with a predetermined password, and email to appropriate recipient.ID Email and Password are found in a CSV file that I created EmailDict from. ID and Filename are parsed and dropped into FileDict.  Any feedback is valued and appreciated. import os import reimport csvimport PyPDF2import smtplibfrom email.mime.text import MIMEText from email.mime.application import MIMEApplicationfrom email.mime.multipart import MIMEMultipart# Create a dictionary with the csv values for ID, Email and PasswordEmailDict = dict()with open('commissionrepemaillist.csv', 'r') as infile:    reader = csv.reader(infile)    for row in reader :        REP = row[0]        EMAIL = row[1]        PASSWORD = row[2]        EmailDict[REP] = EMAIL, PASSWORD# create dictionary of IDs and Pdf FilesFileDict = dict()path = C:\\Apps\\CorVu\\DATA\\Reports\\Monthly Commission Reports\\Output\\pdcom1  for FILE in os.listdir(path):    split = re.split([_.], FILE)    ID = split[1]    FileDict[ID] = FILE# encrypt PDF files in FileDict based on ID and Password from EmailDictfor ID in FileDict:    if ID in EmailDict:        path = C:\\Apps\\CorVu\\DATA\\Reports\\Monthly Commission Reports\\Output\\pdcom1\\        file = os.path.join(path + FileDict[ID])        inputStream = PyPDF2.PdfFileReader(file)        output = PyPDF2.PdfFileWriter()        output.appendPagesFromReader(inputStream)        output.encrypt(EmailDict[ID][1])        with open(file, 'wb') as outputStream:            output.write(outputStream)      else : continue# email encrypted pdf file to appropriate rep for ID in FileDict:    path = C:\\Apps\\CorVu\\DATA\\Reports\\Monthly Commission Reports\\Output\\pdcom1\\    file = os.path.join(path + FileDict[ID])    with open(file, 'rb') as pdf :        pdfAttachment = MIMEApplication(pdf.read(), _subtype = 'pdf')        pdfAttachment.add_header('content-disposition', 'attachment', filename=('MonthlyPaidCommission_%s.pdf' % ID))        text = MIMEText(        For Rep Number : %s         Please use the password previously emailed to open attached file.        If you have any questions or need assistance please contact  me.        Thank you % ID)    msg = MIMEMultipart(_subparts = (text, pdfAttachment))       msg['SUBJECT'] = Commission Report    msg['FROM'] = me@gmail.com    msg['TO'] = EMAIL    s = smtplib.SMTP(LOCALHOST:587)    s.starttls()    s.login('user', 'pwd')    s.sendmail('me@123.com', EMAIL, msg.as_string())    s.quit()
Python code to encrypt and email PDF file using PyPDF2
python;python 2.7;csv;email;pdf