【发布时间】:2020-03-01 16:05:41
【问题描述】:
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')
这是代码。当我尝试运行它时,我收到此错误消息。我真的不知道如何解决这个问题。
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>
我该如何解决这个问题?
【问题讨论】:
-
unexpected indent消息正是它所说的。msg.attach行应该与上面的行有相同的缩进。 -
与
print('Sent to: ',name)相同——它也奇怪地缩进了
标签: python python-3.x pandas