提问者:小点点

我如何打印的文本从功能在电子邮件消息?


对于python来说,这是一个全新的概念,目前正在探索如何从函数中自动发送电子邮件。 每次我发这条消息时,收件箱里的短信只会说“无”。

def attendance_1(*students):

#Would like this message to appear in body of text

print(f"Hello, could you please send out an attendance text to the following student(s) 
please:\n")
for student in students:
    print(f"- {student}")
print("\nThank you very much")

#Info of students 
    example_1 = "example_1@gmail.com"
    example_2 ="example_2@gmail.com"


#Send Message
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)

subject = 'Attendance warning 1'
body = (attendance_1(example_1, example_2))

msg = f'Subject: {subject}\n\n{body}'

smtp.sendmail(SENDER, RECEIVER, msg) 

共1个答案

匿名用户

def attendance_1(students):

    s = f"Hello, could you please send out an attendance text to the following student(s) please:\n"
    for student in students:
        s += f"- {student}"
    s += "\nThank you very much"

    return s

#Info of students 
students = ["example_1@gmail.com", "example_2@gmail.com"]

#Send Message
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)

subject = 'Attendance warning 1'
body = attendance_1(students)

msg = f'Subject: {subject}\n\n{body}'

smtp.sendmail(SENDER, RECEIVER, msg) 

我没有测试这段代码,所以可能会有一些错误。