Advertisement
Guest User

Untitled

a guest
May 29th, 2017
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. import smtplib
  2. import mimetypes
  3.  
  4. from email.MIMEMultipart import MIMEMultipart
  5. from email.mime.application import MIMEApplication
  6. from email.MIMEText import MIMEText
  7. from email.Encoders import encode_base64
  8.  
  9. gente = open('Ingreso.txt', 'r')
  10. for renglon in gente:
  11.    linea = renglon.strip()
  12.    linea = linea.split(',')
  13.    apellido = str(linea[1])
  14.    nombre = str(linea[2])
  15.    mail = linea[4]
  16.    sexo = linea [3]
  17.    if sexo == ' Masculino':
  18.        sexo1 = 'Estimado'
  19.    else:
  20.        sexo1 = 'Estimada'
  21.  
  22. # Construimos un mensaje Multipart, con un texto y una imagen adjunta
  23.    mensaje = MIMEMultipart()
  24.    mensaje['From']="foo@gmail.com"
  25.    mensaje['To']= "foo@gmail.com"
  26.    mensaje['Subject']="Certificado de asistencia"
  27.  
  28. # El texto
  29.    mensaje.attach(MIMEText('''%s gracias por participar...''' % (sexo1 + nombre + apellido)))
  30.  
  31. # Adjuntamos certificado
  32.    nombre_archivo = nombre.decode('utf8') + ' ' + apellido.decode('utf8')
  33.    part = MIMEApplication(open(nombre_archivo,"rb").read())
  34.    part.add_header('Content-Disposition', 'attachment', filename=nombre_archivo)
  35.    mensaje.attach(part)
  36.  
  37.  
  38. # Establecemos conexion con el servidor smtp de gmail
  39.    mailServer = smtplib.SMTP('smtp.gmail.com',587)
  40.    mailServer.ehlo()
  41.    mailServer.starttls()
  42.    mailServer.ehlo()d
  43.    mailServer.login("foo@gmail.com","passwd")
  44.  
  45. # Enviamos el correo, con los campos from y to.
  46.    mailServer.sendmail("foo@gmail.com",
  47.                mail,
  48.                mensaje.as_string())
  49.  
  50. # Cierre de la conexion
  51. mailServer.close()
  52. gente.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement