我正在使用以下代码向 python 中的人发送电子邮件。
import smtplib
from email.mime.multipart import MIMEMultipart, MIMEBase
from email.mime.text import MIMEText
from email.utils import formatdate
def send_mail(send_from,send_to, subject, text, files=[], server = "localhost"):
for s in send_to:
COMMASPACE = ', '
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(s)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
for f in files:
part = MIMEBase('application', "octet-stream")
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' %os.path.basename(f))
msg.attach(part)
server = smtplib.SMTP(server)
server.sendmail(send_from, s, msg.as_string())
server.close()
如果格式混乱,请见谅。emails 是一个包含两封电子邮件的预定义列表。我遇到的错误是:AttributeError: SMTP instance has no attribute 'find'
任何的想法?提前致谢。