首页 > 解决方案 > 如何修复 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)

标签: python

解决方案


推荐阅读