I have a small program that searches through two folders and gets the size of the files in them. As of right now for every file that is over the specified size limit sends a email. What i am wanting to do it have it compile a lsit of the files that are to large and send the list as one email.

import requests, shutil, datetime, glob, os, csv,fnmatch,StringIO,smtplib,argparse, math
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from os import path

parser = argparse.ArgumentParser(description='Search art folders.')
parser.add_argument('-b', help='The base path', required=False, dest='basePath', metavar='Base directory path',default='/home/hatterx/Desktop')
parser.add_argument('--se', help='Change sending emailaddress', required=False, dest='sendEmail', metavar='Sending Emailaddress', default='addon2031@gmail.com')
parser.add_argument('--re', help='Change reciveing emailaddress', required=False,dest='reciveEmail', metavar='Reciveing Emailaddress', default='hatterx@oakleysign.com')
parser.add_argument('--pw', help='Change password', required=False, dest='changePassword', metavar='Change Password', default='jcfutalhndkwsltg')
parser.add_argument('-s', help='Change File size', required=True, dest ='changesize', metavar='Change size', default='0')
args = parser.parse_args()

files = StringIO.StringIO()

def sendEmail(toaddress, subject, body):
    toaddr= toaddress
    msg['Subject']= subject
    body= body
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.login(Sender, Password)
    text = msg.as_string()
    server.sendmail(fromaddr, toaddr, text)

fF = datetime.datetime.now().strftime("%Y%B")
fA = datetime.datetime.now().strftime("%Y%b")

filebase = args.basePath
fileFull = filebase+'/'+fF.upper()+'JPG'
fileAbriv = filebase+'/'+fA.upper()+'JPG'
Reciver = args.reciveEmail
Sender = args.sendEmail
Password = args.changePassword

def fileSearch(filename):

    for fileName in glob.iglob("*"):
        dirname, filenamE = os.path.split(fileName)
        SUBJECT = 'File size'
        statinfo = os.stat(fileName)
        numToString = str(statinfo.st_size/1024)
        BODY = 'The following list of files are to large: '+files.readline()
        print (str(statinfo.st_size/1024))+'KB'
        print (filename)+'/'+(filenamE)
        if args.changesize >= str(statinfo.st_size/1024):
            sendEmail(args.reciveEmail, SUBJECT, BODY)
        elif args.changesize < str(statinfo.st_size/1024):
    print 'These files are the correct size please check email for files that are to large.'

Why you are using StringIO here? Just build the string normally and send it.
Python pseudo-code:

send_mail(address, subject,'\n'.join(info_i_want(big_file) for big_file in list_of_files if size_of(big_file) > SIZE_LIMIT)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.