0

I want to make a script that sends my homework to my mail every now and then, but they sending a mail part isn't working. I have looked at tutorials, but I still get a mistake when i write msg = MIMEMultipart() Is there something wrong with that? (I use gmail)

for name, email in zip(names, emails):
    print("Writing the mail")

    msg = MIMEMultipart()

    # add in the actual person name to the message template
    message = message_template.substitute(PERSON_NAME=name.title())

    # setup the parameters of the message
    msg['From']=Myaddress
    msg['To']=email
    msg['Subject']="Homework"

    # add in the message body
    msg.attach(MIMEText(message, 'plain'))

    # send the message via the server set up earlier.
    s.send_message(msg)
    print("Mail sent")

    del msg

btw I have multiple mails to send it to. And yes I imported these:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
Sebastian
  • 1
  • 1
  • But Which is the error you have? – GiovaniSalazar Dec 13 '19 at 12:51
  • Unindent does not match any outer indentation level (, line 139) pylint(syntax-error) [139, 27] And line 139 is msg = MIMEMultipart() – Sebastian Dec 13 '19 at 12:55
  • This might help https://stackoverflow.com/questions/3362600/how-to-send-email-attachments – Priyanka Khairnar Dec 13 '19 at 12:59
  • I dont see how it helps, because he does the same as me: msg = MIMEMultipart() – Sebastian Dec 13 '19 at 13:06
  • Does this answer your question? [IndentationError: unindent does not match any outer indentation level](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) – stovfl Dec 13 '19 at 13:12
  • can you add all your code ? ..pls – GiovaniSalazar Dec 13 '19 at 13:13
  • But now I get a new error, too long to type it in here - something about authentication – Sebastian Dec 13 '19 at 13:20
  • Is gmail ?...check this - > https://stackoverflow.com/questions/59270643/python-smtpauthnticationerror/59271554#comment104752676_59271554 – GiovaniSalazar Dec 13 '19 at 13:23
  • This is where I get the error: `s = smtplib.SMTP(host="smtp.gmail.com", port=465)` `s.starttls()` `s.login(Myaddress, Mailpassword)` – Sebastian Dec 16 '19 at 09:51
  • I just did what I should in the link - allow less secure apps, but I still get an error `s = smtplib.SMTP(host="smtp.gmail.com", port=465)` in this line of code. Any idea why? – Sebastian Dec 16 '19 at 13:07
  • TimeoutError: [WinError 10060] – Sebastian Dec 16 '19 at 13:17
  • Ok, somehow it works when just switching to a different pc, probably because my old pc was waaay too slow for the server to start up before taking too long time. Thanks for the help though, thanks :) – Sebastian Dec 16 '19 at 15:03

0 Answers0