0
我試圖在電子郵件中插入select語句。表 有10行和3列,但我無法做到這一點。下面的代碼和錯誤。通過電子郵件發送mysql的select語句
#!/usr/bin/env python
import csv
import MySQLdb
import pysftp
import smtplib
import sys
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
conn = MySQLdb.connect(XXXX)
#Email Part1 Msg
part1 = """
To: To Person <>
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP HTML e-mail test
"""
sender = ''
receivers =
x = conn.cursor()
query1= ("""select * from table""")
smtpObj=smtplib.SMTP('smtp', 25)
smtpObj.sendmail(sender, receivers, x.execute(query1))
這是錯誤訊息:
Traceback (most recent call last):
File "test3.py", line 33, in <module>
smtpObj.sendmail(sender, receivers, x.execute(query1))
File "/usr/lib/python2.7/smtplib.py", line 729, in sendmail
esmtp_opts.append("size=%d" % len(msg))
TypeError: object of type 'long' has no len(
分離代碼與說明;澄清說明文字。 –