• Stan

    Amazing ! It works perfectly !

    Thank you very much dgelessus to have taken time to write the answer. It solved my problem.

    posted in Pythonista read more
  • Stan

    Hello,

    My name is Stan and i am a mathematic teacher.
    i want to send 30 different pdf to 30 different students ( one file to each student)
    I have a code using the module MIME
    that i founded online and that i modificated a bit adding a loop. i put this code attached to this message.
    But my problem is that this code uses the path of a file like \ users\Stan\dropbox....
    So it’s working good on a mac but not on the ipad.

    i would like to know if there is a way to make it work on ipad ? i am quite a newbie in coding.

    thank you very much in advance.

    # -*- coding: utf-8 -*-
    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.base import MIMEBase
    from email import encoders
    
    fromaddr = '''my mail adress'''
    classe=input('enter the class: ts ou sec ou spe')
    if classe=="ts":
      toaddrs='''list of the mail adresses'''
      filenames = '''list of my files'''
      paths='''list of the paths of the files like : \users\jean......'''
      n=len(paths)
    if classe=='sec':
      toaddrs='''list of the mail adresses'''
      filenames = '''list of my files'''
      paths='''list of the paths of the files like : \users\jean......'''
      n=len(paths)
    if classe=="spe":
        toaddrs='''list of the mail adresses'''
      filenames = '''list of my files'''
      paths='''list of the paths of the files like : \users\jean......'''
      n=len(paths)
     
    for k in range(n):
      msg = MIMEMultipart()
      msg['From'] = fromaddr
      msg['To'] = toaddrs[k]
      msg['Subject'] = '''the subject'''
      body = '''body of the mail'''
      msg.attach(MIMEText(body, 'plain'))
      attachment = open(paths[k], "rb")
      filename=filenames[k]
      toaddr=toaddrs[k]
      part = MIMEBase('application', 'octet-stream')
      part.set_payload((attachment).read())
      encoders.encode_base64(part)
      part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
      msg.attach(part)
      server = smtplib.SMTP('smtp.gmail.com', 587)
      server.starttls()
      server.login(fromaddr, '''my password''')
      text = msg.as_string()
      server.sendmail(fromaddr, toaddr, text)
      server.quit()
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!