-1
import smtplib, ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from secrets import mycred

file=pd.read_excel('emails.xlsx',sheet_name='Sheet1')
contacts=pd.DataFrame(file)
password = mycred()[1]

for i in range(len(contacts)):
    name, email, address=contacts.iloc[i]
    port = 587 # For SSL
    smtp_server = "smtp.mail.com"
    msg = MIMEMultipart()
    msg['From'] = mycred()[0]
    msg['To'] = email
    msg['Subject'] = "TEST"
    body = "Hey {}, how is it going? I just wanted to confirm your infromationAre you still at{}?" .format(name.split()[0],address)

           msg.attach(MIMEText(body, 'plain'))
           text = msg.as_string()
           context = ssl.create_default_context()
           with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
               server.login(mycred()[0], password)
               server.sendmail(mycred()[0], msg['To'] , text)
            print('Sent to: ',name)
        print('Done')

This is the code. And the i get this error message when i try to run it. I really don't know how to fix this.

 File "c:/Users/rasmu/OneDrive/Dokumenter/VS Projekter/mailtest/emailer.py", line 21
   message.attach(MIMEText(body, 'plain'))
   ^
IndentationError: unexpected indent
PS C:\Users\rasmu\OneDrive\Dokumenter\VS Projekter\mailtest>  

How can i fix this?

1 Answers1

0

Python language is very strict in structure of the code. It means that you need to 'TAB' - indent your code in structure way. Probably the 'empty' line gives this error: delete it, un-indent the block of code afterwards, save the source file and retry to run it.

Use indentation when you have for loops or if-else statements.

see examples at: [https://docs.python.org/2.0/ref/indentation.html][1]

Itzik Chaimov
  • 89
  • 1
  • 10