python通过外部参数发送邮件

#!/usr/bin/python

#coding:utf8

#file topid.py

import smtplib,mimetypes     #mail module

import time            #system time   

import sys,os 

from email.mime.text import MIMEText  #mail type mode

from email.mime.multipart import MIMEMultipart

from email.mime.image import MIMEImage


#sys and date messages

datetime = time.strftime('%Y-%m-%d %H:%M:%S')  #get time 

dataname = "tlcytop"

#mail messages

msg = MIMEMultipart()

msg['From'] = "[email protected]

msg['To'] = "[email protected]

msg['Subject'] = "dataname %s time %s" %(dataname,datetime) 


smtp = smtplib.SMTP()

smtp.connect("smtp.audiocn.com")

smtp.login("[email protected]",'password')


a=sys.argv[1] #传递参数

a=int(a)   #数据类型转换

if (a < 450):

#ddprint "ok %s" % (a) 

txt = MIMEText("Subject: %s tlcytop.edit_ugc-------->updatetime<450   updatetime= %s" % (datetime,a ))

msg.attach(txt)

smtp.sendmail('[email protected]', '[email protected]',msg.as_string())

smtp.sendmail('[email protected]', '[email protected]',msg.as_string()) #发送邮件

smtp.quit()


调用python的shell脚本

#/bin/bash

#

#a=`/usr/bin/mysql -uroot  -p123456 -e "select count(user) from mysql.user;" |sed -n '2p'`


a=`/usr/bin/mysql -uxxx -hxxx -pxxxx -e "select COUNT(*) from tlcytop.edit_ugc where updatetime > '2016-01-07 00:00:00'" |sed -n '2p'`

source ~/.bashrc && /usr/bin/python /home/tiantao/mysqldcheck.py $a


你可能感兴趣的:(python,发送邮件,外部参数)