我尝试用 Python 编写脚本,谁:
连接到火鸟数据库
在连接的数据库中执行选择
通过 SELECT 为数据库 rerutn 中的每个结果记录发送电子邮件。
我使用:Windows Vista x64 SP2,Python 版本 3.5.1,firebird 驱动程序 fdb 1.5.1。
使用以下脚本后,我收到电子邮件:fdb.fbcore.Cursor object at 0x00175BB0
请提出建议。
# -*- coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
import fdb
con = fdb.connect(host='127.0.0.1', database='test', user='SYSDBA', password='masterkey', charset='WIN1250')
to = ['xxxxxx@xxxxxx']
cc = ['xxxxxx@xxxxxx']
bcc = ['xxxxxx@xxxxxx']
from_addr = 'xxxxxx@xxxxxx'
message_subject = "Say Hello"
cur = con.cursor()
select = cur.execute("select telephone from person")
#message_text = "%a" % (select)
message_text = (select)
message = "From: %s\r\n" % from_addr \
+ "To: %s\r\n" % ",".join(to) \
+ "CC: %s\r\n" % ",".join(cc) \
+ "BCC: %s\r\n" % ",".join(bcc) \
+ "Subject: %s\r\n" % message_subject \
+ str(message_text)
to_addrs = to + cc + bcc
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('xxxxxx','xxxxxx')
#server.set_debuglevel(1)
#for message_text in cur.fetchall():
# print(message_text)
for message_text in cur.fetchall():
server.sendmail(from_addr, to_addrs, message)
server.quit()
con.close()