将Python中的打印消息传递给电子邮件

时间:2014-09-10 13:54:23

标签: python

我写了一个python脚本,里面有几个print语句。我想将这些打印语句传递给脚本在运行完毕后发送给我的电子邮件。这可能吗?

以下是我的尝试,它在已删除=

时出错
import arcpy, os
arcpy.DeleteRows_management(r"C:\GIS_Work\StreetsTesting\Lake George.shp")

deleted = print "The rows have been deleted from Lake George"

# Send Email when script is complete
SERVER = "my.mailserver.com"
FROM = "from@email.com>"
TO = "to@email.com>"
SUBJECT = "The Script Has Completed"
MSG = deleted

# Prepare actual message
MESSAGE = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, MSG)

# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, MESSAGE)
server.quit()

0 个答案:

没有答案