python电子邮件_Python电子邮件发送

我正在创建帐户创建者。我希望我可以创建一个电子邮件发件人,以便人们在填写表格后收到电子邮件,

这就是我尝试过的:# 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电子邮件发送者的其他问题有很多,但没有一个像我一样有相同的问题/错误。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值