尝试将电子表格内容邮寄为邮件正文。
代码示例:
import smtplib
from email.mime.text import MIMEText
import mimetypes
from email import encoders
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import csv
import os
import io
import codecs
fileMsg = MIMEBase("application","octet-stream")
with open('123.xls','r') as fp:
contents = fp.read()
fileMsg = MIMEText(contents)
outer.attach(fileMsg)
但收到错误消息:
contents = fp.read()
File "\\ms\dist\python\PROJ\core\3.4.2-4-64\.exec\ia32.nt.4.0\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 756: character maps to <undefined>
msg的正文应该与电子表格一样..还需要根据工作表名称获取...请帮助..