import arcgisscripting, smtplib, os, sys, traceback

from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders gp = arcgisscripting.create(9.3) #**********************************************************************
# Description:
# Emails a file. File is assumed to be a zip file. Routine either attaches
# the zip file to the email or sends the URL to the zip file.
#
# Parameters:
# 1 - File to send.
# 2 - Email address to send file.
# 3 - Name of outgoing email server.
# 4 - Output boolean success flag.
#********************************************************************** def send_mail(send_from, send_to, subject, text, f, server, smtpUser="", smtpPwd=""):
try:
msg = MIMEMultipart()
msg['From'] = send_from
msg['To'] = COMMASPACE.join(send_to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject msg.attach( MIMEText(text) )
part = MIMEBase('application', "zip") # Change if different file type sent.
part.set_payload( open(f,"rb").read() )
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
msg.attach(part) smtp = smtplib.SMTP(server) # If your server requires user/password
if smtpUser != "" and smtpPwd != "":
smtp.login(smtpUser, smtpPwd) smtp.sendmail(send_from, send_to, msg.as_string())
smtp.close()
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + \
str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
raise Exception("SendEmailError:" + pymsg) if __name__ == '__main__': sendto = gp.GetParameterAsText(0).split(";")
fromaddr = gp.GetParameterAsText(1)
subject = gp.GetParameterAsText(2)
text = gp.GetParameterAsText(3)
zipfile = gp.GetParameterAsText(4).replace("\\",os.sep)
maxsize = int(gp.GetParameterAsText(5)) * 1000000
smtpMailServer = gp.GetParameterAsText(6)
smtpUser = gp.GetParameterAsText(7)
smtpPwd = gp.GetParameterAsText(8) try:
zipsize = os.path.getsize(zipfile)
#Message"Zip file size = "
gp.AddMessage(gp.GetIDMessage(86156) + str(zipsize))
if zipsize <= maxsize:
send_mail(fromaddr, sendto, subject, text, zipfile, smtpMailServer, smtpUser, smtpPwd)
#Message "Sent zipfile to %s from %s"
gp.AddIDMessage("INFORMATIVE", 86154, sendto, fromaddr)
gp.SetParameterAsText(9, "True")
else:
#Message "The resulting zip file is too large (%sMB). Must be less than %MB. Please
# digitize a smaller Area of Interest."
gp.AddIDMessage("ERROR", 86155, str(round(zipsize / 1000000.0, 2)),
str(round(maxsize / 1000000.0, 2)))
gp.SetParameterAsText(9, "False")
raise Exception except:
# Return any python specific errors as well as any errors from the geoprocessor
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + \
str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"
gp.AddError(pymsg)
#Message "Unable to send email"
#gp.AddIDMessage("ERROR", 86157)
gp.AddError("ERROR, Unable to send email")

arcgis python 发送邮件的更多相关文章

  1. python发送邮件

    python发送邮件(无附件) ======================================================= #!/usr/bin/env python#coding ...

  2. python发送邮件及附件

    今天给大伙说说python发送邮件,官方的多余的话自己去百度好了,还有一大堆文档说实话不到万不得已的时候一般人都不会去看,回归主题: 本人是mac如果没有按照依赖模块的请按照下面的截图安装 导入模块如 ...

  3. python 发送邮件实例

    留言板回复作者邮件提醒 -----------2016-5-11 15:03:58-- source:python发送邮件实例

  4. 解读Python发送邮件

    解读Python发送邮件 Python发送邮件需要smtplib和email两个模块.也正是由于我们在实际工作中可以导入这些模块,才使得处理工作中的任务变得更加的简单.今天,就来好好学习一下使用Pyt ...

  5. python 发送邮件例子

    想到用python发送邮件 主要是服务器 有时候会产生coredump文件  ,然后因为脚本重启原因,服务器coredump产生后会重启 但是没有主动通知开发人员 想了下可以写个脚本一旦产生cored ...

  6. 利用python发送邮件

    找了很多使用python发送邮件的文章, 发现写的并不是太全, 导致坑特别多, 刚把这个坑跨过去, 在此记录下来 本代码使用163作为发送客户端, 接收邮箱随意 首先登录163邮箱, 开启POP3/S ...

  7. 用Python发送邮件

    文件:send.py # -*- coding:utf-8 -*- # ## 任兴测试用Python发送邮件 import os import sys import getopt import tim ...

  8. ETL过程跑完后,使用python发送邮件

    目标库中,如果有行数为0的表,使用python发送邮件 # -*- coding:utf-8 -*- # Author: zjc # Description:send monitor info to ...

  9. arcgis python arcpy add data script添加数据脚本

    arcgis python arcpy add data script添加数据脚本mxd = arcpy.mapping.MapDocument("CURRENT")... df ...

随机推荐

  1. 面试常考HTTP协议知识点

    协议简介 1. 应用层协议, 一般以TCP为基础,数据收发通过TCP实现: 2. 一次性连接.服务器与客户端的每次连接只处理一个请求,下次请求重新建立连接: 3. 无状态协议.服务器不保留与客户交易时 ...

  2. 苹果APP内购客户付款成功,没收到相应虚拟产品的解决办法

    一.引导用户走申请苹果的退款 1.告知用户新版本可以使用支付宝.微信支付,更划算 2.苹果可申请90天以内的退款,一般情况申请后48小时内就有反馈. 参考链接 https://jingyan.baid ...

  3. RocketMQ问题

    RocketMQ原理(4)——消息ACK机制及消费进度管理 RocketMQ消费者,设置setConsumeFromWhere无效的问题 MQ的CONSUME_FROM_LAST_OFFSET未生效 ...

  4. {T4模板}C# Net MVC+SqlServer=T4模板生成实体类并操作数据(DbHelper+DBManage)

    1.ConnectionString,数据库链接 Web.config <configuration> <connectionStrings> <!-- 数据库 SQL ...

  5. Hbase Region in transition问题解决

    1  hbase hbck -repair 强制修复 如果ok就可以 2 不ok,找到hdfs上对应的该表位置,删除,之后在使用hbase hbck -repair 解决过程: 第一次,使用了方法二, ...

  6. TLS1.3 认证和秘钥建立握手环节的分析

    1.ClientHello 中的参数 ClientHello---{   Random_C .extension }   在 extension中的扩展中包含 ( supported_version ...

  7. DNS服务——域名解析容错

    介绍 DNS服务至关重要,你我每天访问网站不可能是记忆IP地址.因此DNS服务器的可靠性至关重要.下面介绍DNS服务器容错机制,看图 为了防止DNS服务器故障不再提供服务,引入辅助DNS服务器.辅助D ...

  8. C++——友元 friend

    人类社会的friend VS C++世界的friend 现实世界中,我们自己很多物品,朋友是可以使用的,但是陌生人就不行.那么money,朋友可以随便拿吗?这要是你和friend的关系深浅而定.人类社 ...

  9. ES6中let、const和var的区别

    一.let 1.基本用法 ES6 新增了let命令,用来声明变量. let 的用法类似于 var,但所声明的变量只在 let 命令所在的代码块内有效(一个“{}”相当于一个代码块) { let a = ...

  10. G1垃圾收集器原理剖析【官方解读】

    继续基于上一次https://www.cnblogs.com/webor2006/p/11135005.html的官方G1文档进行解读,上一次分析到了这: 话不多说,继续往前读: When perfo ...