我正在创建帐户创建者。我希望我可以创建一个电子邮件发件人,以便人们在填写表格后收到电子邮件,
这就是我尝试过的:# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
fp = open('textfile.txt', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
我尝试将文件重命名为main.py,
但是我得到了一个错误:
^{pr2}$
当我把文件名改为主.py
我得到了错误:Traceback (most recent call last):
File "/Users/macbook/Movies/GAME/Wonderland/3D/main.py", line 11, in
msg = MIMEText(fp.read())
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/email/mime/text.py", line 33, in __init__
_text.encode('us-ascii')
AttributeError: 'bytes' object has no attribute 'encode'
python电子邮件发送者的其他问题有很多,但没有一个像我一样有相同的问题/错误。在