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. 【leetcode】366.Find Leaves of Binary Tree

    原题 Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all lea ...

  2. c语言int类型的变量输入一个字符出错

    今天遇到一个C语言的小问题,就是写一个简单的计算器,定义一个%f%c%f的三个变量,作2+3,2-3这种可以不断输入并输入“OFF”跳出循环的计算器功能,便会出现错误: 错误的示例代码如下: #inc ...

  3. Linux命令——set 和 unset

    参考:Linux set and unset http://www.runoob.com/linux/linux-comm-set.html https://blog.csdn.net/u010003 ...

  4. httpd基于域名不同的虚拟主机配置

    apache2.2.x版本 1. 注释主配置文件/etc/httpd/conf/httpd.conf中的 DoucumentRoot #DocumentRoot "/var/www/html ...

  5. 3D Experience — 产品协同研发平台

    随着产品复杂程度的提升,市场竞争愈加激烈,基于模型的正向研发已经作为有效的应对手段被广泛接受.但研发流程中仍然存在复杂功能架构定义困难.多方案难以权衡.多系统难以联合仿真,仿真效率低,验证不充分等问题 ...

  6. SLAM面试常见问题

    之前我们分享过视觉SLAM找工作.面试经历,见<2018年SLAM.三维视觉方向求职经验分享>,<经验分享 | SLAM.3D vision笔试面试问题>. 从零开始学习SLA ...

  7. can't assign to struct fileds in map

    原文: https://haobook.readthedocs.io/zh_CN/latest/periodical/201611/zhangan.html --------------------- ...

  8. 设计模式之命令模式-JS

    理解命令模式 假设有一个快餐店,而我是该餐厅的点餐服务员,那么我一天的工作应该是这样的:当某位客人点餐或者打来订餐电话后,我会把他的需求都写在清单上,然后交给厨房,客人不用关心是哪些厨师帮他炒菜.我们 ...

  9. TDOA Delayed Tx 实现以及验证

    在博文:https://www.cnblogs.com/tuzhuke/p/11638221.html 中描述了delayed tx实现方法,这里贴出全部delayed tx 代码以及对应验证代码 1 ...

  10. SQL:自增主键的获取@@IDENTITY 和 SCOPE_IDENTITY 的区别

    @@IDENTITY 返回当前会话所有作用域的最后一个ID SCOPE_IDENTITY() 返回当前作用域的最后一个ID 返回上面语句执行后产生的自增主键,这个是目前最可靠的方式: insert i ...