arcgis python 发送邮件
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 发送邮件的更多相关文章
- python发送邮件
python发送邮件(无附件) ======================================================= #!/usr/bin/env python#coding ...
- python发送邮件及附件
今天给大伙说说python发送邮件,官方的多余的话自己去百度好了,还有一大堆文档说实话不到万不得已的时候一般人都不会去看,回归主题: 本人是mac如果没有按照依赖模块的请按照下面的截图安装 导入模块如 ...
- python 发送邮件实例
留言板回复作者邮件提醒 -----------2016-5-11 15:03:58-- source:python发送邮件实例
- 解读Python发送邮件
解读Python发送邮件 Python发送邮件需要smtplib和email两个模块.也正是由于我们在实际工作中可以导入这些模块,才使得处理工作中的任务变得更加的简单.今天,就来好好学习一下使用Pyt ...
- python 发送邮件例子
想到用python发送邮件 主要是服务器 有时候会产生coredump文件 ,然后因为脚本重启原因,服务器coredump产生后会重启 但是没有主动通知开发人员 想了下可以写个脚本一旦产生cored ...
- 利用python发送邮件
找了很多使用python发送邮件的文章, 发现写的并不是太全, 导致坑特别多, 刚把这个坑跨过去, 在此记录下来 本代码使用163作为发送客户端, 接收邮箱随意 首先登录163邮箱, 开启POP3/S ...
- 用Python发送邮件
文件:send.py # -*- coding:utf-8 -*- # ## 任兴测试用Python发送邮件 import os import sys import getopt import tim ...
- ETL过程跑完后,使用python发送邮件
目标库中,如果有行数为0的表,使用python发送邮件 # -*- coding:utf-8 -*- # Author: zjc # Description:send monitor info to ...
- arcgis python arcpy add data script添加数据脚本
arcgis python arcpy add data script添加数据脚本mxd = arcpy.mapping.MapDocument("CURRENT")... df ...
随机推荐
- FreeRTOS 任务创建和删除(静态)
#define configSUPPORT_STATIC_ALLOCATION 1 //打开静态方法 StackType_t TaskStackBuffer[50]; //任务堆栈大小 StaticT ...
- 安装配置nginx之后访问不了nginx的问题
我刚开通的服务器,没有设置安全组规则. 进入云服务控制台 配置规则 其他不要动,授权对象加0.0.0.0/0 就可以访问nginx了
- Image Processing and Computer Vision_Review:A Performance Evaluation of Local Descriptors——2005.08
翻译 本地描述符的性能评估——http://tongtianta.site/paper/56756 摘要 - 在本文中,我们比较了为局部感兴趣区域计算的描述符的性能,例如,由Harris-Affine ...
- Python函数Day4
一.内容补充 __iter__() 就是 iter(),iter() 调用的就是__iter__() __next__() 就是 next(),next()调用的就是__next__() __clos ...
- springboot集成rabbitmq并手动注册容器实现单个queue的ack模式
原文:https://blog.csdn.net/qq_38439885/article/details/88982373 进入正题,本文会介绍两种实现rabbitmq的ack模式的方法,分别为: 一 ...
- docker 安装elk
https://www.cnblogs.com/fbtop/p/11005469.html
- BZOJ 2321 星器
星器 思路: 势能分析法. 假设每颗星星的势能为\(x^2+y^2\) 那么对于一行的两颗星星\((i, j), (i, k), j < k\) 它转移到\((i, j+1), (i, k-1) ...
- Selenium常用API的使用java语言之14-多窗口切换
在页面操作过程中有时候点击某个链接会弹出新的窗口, 这时就需要主机切换到新打开的窗口上进行操作.WebDriver提供了switchTo().window()方法可以实现在不同的窗口之间切换. 以百度 ...
- Selenium常用API的使用java语言之12-定位一组元素
在第(五)节我们已经学习了8种定位方法, 那8种定位方法是针对单个元素定位的, WebDriver还提供了另外8种用于定位一组元素的方法. import org.openqa.selenium.By; ...
- czy的后宫——矩阵快速幂优化DP
题意 有 n 个位置排成一行,可以放 m 种妹子.每个位置可以放也可以不放,规定某些妹子不能相邻,求方案数. 分析 #include<bits/stdc++.h> using namesp ...