电子表格数据到电子邮件正文 - Python

时间:2016-09-15 17:34:40

标签: excel python-2.7 python-3.x email spreadsheet

尝试将电子表格内容邮寄为邮件正文。

代码示例:

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>

我尝试提取的内容采用表格格式,如: enter image description here

msg的正文应该与电子表格一样..还需要根据工作表名称获取...请帮助..

0 个答案:

没有答案