Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/05/2010, 09:15
Avatar de Nekeniehl
Nekeniehl
 
Fecha de Ingreso: julio-2009
Ubicación: Berlin, Alemania / Granada, España
Mensajes: 132
Antigüedad: 14 años, 10 meses
Puntos: 6
Help, envio de emails...

Veamos tengo dos funciones, asi rapido..la primera encripta un archivo y llama a la segunda que manda ese archivo por mail..acto seguido mueve los archivos a una carpeta Old pero antes comprueba que la segunda funcion no tenga errores y el caso es que siempre devuelve error, alguna mente dispuesta a ayudarme sobre que hago mal?

Código Python:
Ver original
  1. def SendMail():#to, subject, text, files=[],server="localhost"):
  2.     numFiles= os.listdir('~/ReportingTool/Logs/')
  3.     dirFil='~/ReportingTool/Logs/'
  4.     dirOld='~/ReportingTool/Logs/Old/'
  5.     dirEnc='~/ReportingTool/Encfiles/'
  6.     for cont in numFiles:
  7.         if (os.path.isfile(os.path.join(dirFil,cont))):
  8. #           Encrypt all files to send via email
  9.             filin=dirFil+cont
  10.             filout=dirEnc+cont
  11.             Encrypt("xxxxxxxx", filin, filout)
  12.     filout=dirEnc+"25-05-2010.Tuesday"
  13.     if (Send ("[email protected]","Report", "See reports attached.", filout)):
  14.         #    Move files to dir Old
  15.         mvin=os.path.join(dirFil,cont)
  16.         mvout=os.path.join(dirOld,cont)
  17.         shutil.move(mvin,mvout)
  18.  
  19. def Send(to, subject, text, files,server="localhost"):
  20. #    assert type(to)==list
  21. #    assert type(files)==list
  22.     fro = "[email protected]"
  23.  
  24.     msg = MIMEMultipart()
  25.     msg['From'] = fro
  26.     msg['To'] = COMMASPACE.join(to)
  27.     msg['Date'] = formatdate(localtime=True)
  28.     msg['Subject'] = subject
  29.  
  30.     msg.attach( MIMEText(text) )
  31.  
  32.  
  33.     part = MIMEBase('application', "octet-stream")
  34.     part.set_payload( open(files,"rb").read() )
  35.     Encoders.encode_base64(part)
  36.     part.add_header('Content-Disposition', 'attachment; filename="%s"'% os.path.basename(files))
  37.     msg.attach(part)
  38.  
  39.     smtp = smtplib.SMTP(server)
  40.     error=True
  41.     if (smtp.sendmail(fro, to, msg.as_string())):
  42.         error=False;
  43.     smtp.close()
  44.     if (error==False):
  45.         return True
  46.     else:
  47.         return False