python - 如何修复 NameError:未定义名称“名称”
问题描述
我正在尝试为我的编程课程制作一个程序,在该课程中我制作一封自动电子邮件以发送给多个人的电子邮件。但是,它说名称没有定义,我无法弄清楚我做错了什么,有人可以帮忙。代码粘贴在下面
#!/usr/bin/env python3
def get_contacts(emails):
names = []
emails = []
MY_ADDRESS = noreply@deals.com
with open(filename, mode='r', encoding='utf-8') as contacts_file:
for a_contact in contacts_file:
names.append(a_contact.split()[0])
emails.append(a_contact.split()[1])
return names, emails
from string import Template
def read_template(email_template):
with open(filename, 'r', encoding='utf-8') as template_file:
template_file_content = template_file.read()
return Template(template_file_content)
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# For each contact, send the email:
for nameS, emailS in zip(names, emails):
msg = MIMEMultipart() # create a message
# 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']=MY_ADDRESS
msg['To']=email
msg['Subject']="This is TEST"
# add in the message body
msg.attach(MIMEText(message, 'plain'))
# send the message via the server set up earlier.
s.send_message(msg)
解决方案
推荐阅读
- javascript - 如何创建与 vue 路由器一起使用的子组件?
- ruby-on-rails - 从 chromedriver-helper 到 webdriver 的 Rails 更新显示 W3C 标准错误
- highcharts - 格式化 highcharts 日期工具提示以显示时区
- python - 如何在 Jupyter Notebook 中运行系统命令并获得连续输出?
- ios - 用避雷线连接midi
- javascript - Using window.open() "windowFeatures" parameter and trying to remove about:blank
- xml - Notepad++ XML Tools 插件解析 windows-1251 的编码器错误
- sql-server - SQL Server 企业版是否符合 FISMA?
- eclipse - 如何收听“项目资源管理器”插件中的比较事件?
- php - 仅在帖子类型页面中显示产品价格元素