Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 用Python SMTP发送我的第一封电子邮件-使用;加上;是无效语法吗?_Python 3.x_Email - Fatal编程技术网

Python 3.x 用Python SMTP发送我的第一封电子邮件-使用;加上;是无效语法吗?

Python 3.x 用Python SMTP发送我的第一封电子邮件-使用;加上;是无效语法吗?,python-3.x,email,Python 3.x,Email,我在网上关注一门课,我在做老师做的事情。他们使用with块来发送这段代码,但它给了我一个语法错误。我不明白我做错了什么,我遵循了完全相同的步骤 from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib #Replaced email, name, & password w/ filler message = MIMEMultipart() mes

我在网上关注一门课,我在做老师做的事情。他们使用with块来发送这段代码,但它给了我一个语法错误。我不明白我做错了什么,我遵循了完全相同的步骤

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

您在message.attach(MIMEText(“Body”)中缺少一个右括号