我在网上听课,我是按照讲师的方式去做的。他们对这段代码使用了with块来发送电子邮件,但它给了我一个SyntaxError。我不明白我在这里做错了什么,我遵循了完全相同的步骤。
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
#Replaced email, name, & password w/ filler
message = MIMEMultipart()
message["from"] = "First_Name Last_Name"
message["to"] = "email@email.com"
message["subject"] = "This is a test"
message.attach(MIMEText("Body")
with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login("email@email.com", "password1234")
smtp.send_message(message)
print("Sent...")
下面是我得到的错误:
File "c:\Users\Mofongo\Google Drive\HelloWorld\app.py", line 11
with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp:
^
SyntaxError: invalid syntax
发布于 2020-10-06 08:52:31
message.attach(MIMEText("Body"))中缺少右括号。
https://stackoverflow.com/questions/64217904
复制相似问题