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 ...
随机推荐
- Linux日志查看
Linux日志查看: 1.Last -a 把从何处登入系统的主机名称或IP地址,显示在最后一行.-d 指定记录文件.指定记录文件.将IP地址转换成主机名称.-f <记录文件> 指定记录文 ...
- RuntimeWarning: DateTimeField AppToken.expire_date received a naive datetime (2019-05-16 16:54:01.144582) while time zone support is active. RuntimeWarning)
数据库存储当前时间操作: datetime.datetime.now() 更改为: from django.utils import timezone timezone.now()
- mycat使用--schema配置
<?xml version="1.0"?> <!DOCTYPE schema SYSTEM "schema.dtd"> -<myc ...
- windows 下 redis 的安装及使用
1.下载及安装redis 下载地址:https://github.com/dmajkic/redis/downloads 找到对应的版本下载安装 打开cmd窗口,用cd命令进入到安装redis的根目录 ...
- springboot系列(十)springboot整合shiro实现登录认证
关于shiro的概念和知识本篇不做详细介绍,但是shiro的概念还是需要做做功课的要不无法理解它的运作原理就无法理解使用shiro: 本篇主要讲解如何使用shiro实现登录认证,下篇讲解使用shiro ...
- Linux系统硬链接和软链接说明 - 运维笔记
在linux系统中有种文件是链接文件,可以用来解决文件的共享使用.链接的方式可以分为两种,一种是硬链接(Hard Link),另一种是软链接或者也称为符号链接(Symbolic Link).先来查看下 ...
- webpack中如何编写一个plugin
loader和plugin有什么区别呢?什么是loader,什么是plugin. 当我们在源代码里面去引入一个新的js文件或者一个其他格式的文件的时候,这个时候,我们可以借助loader去帮我们处理引 ...
- 开源框架---tensorflow c++ API中./configure步骤细节
u@u160406:~/tf1.13/tensorflow$ git checkout r1.13 分支 r1.13 设置为跟踪来自 origin 的远程分支 r1.13.切换到一个新分支 'r1.1 ...
- Maven创建本地仓库
1:创建仓库目录 在D盘Program Files目录下创建repository目录 2:修改settings.xml D:\ProgramFiles\repository 是我们创建的本地 ...
- js for/in循环及其它
for in 循环不仅可以遍历对象的属性,还可以遍历数组. Js 中为数组提供了多种遍历方式 const ary = ['a', 'b', 'c']; // 最基本的方式, 只能遍历下标有序递增的数组 ...