随人Linux自带了功能强大的sendmail服务器,但是这样发送的邮件往往被视为垃圾邮件。以下代码可以登录你的邮箱发送邮件,并且可以添加抄送人,添加附件,可以发给多个收件人。其中:
邮件的正文在/app/opt/oracle/mail.txt 中 ,/app/opt/oracle/report.zip是的附件。
- DECLARE
- pass VARCHAR2(20) := 'Z1234';--????
- BEGIN
- FOR c IN (select a.username from dba_users a,icaps_user b where 'Z'||b.username=a.username ) LOOP
- EXECUTE IMMEDIATE 'alter user ' || c.username || ' identified by ' || pass;
- END LOOP;
- END;
-
-
-
-
-
- #!/usr/bin/env python
- import smtplib,mimetypes
- from email import Encoders
- from email.MIMEBase import MIMEBase
- from email.MIMEText import MIMEText
- from email.MIMEMultipart import MIMEMultipart
- import email
- import time
-
- femail='xxx@xxxx.com'
- temail =['yyyyy@yyyy.com','sssss@ssss.com']
- ccmail=['zzzzz@zzzzz.com','ggggg@ggggg.com']
-
- to_string =''
- for item in temail:
- to_string += item +','
-
-
- cc_string =''
- for item1 in ccmail:
- cc_string += item1 +','
-
- msg=MIMEMultipart()
- msg['From'] = femail
- msg['To'] = to_string
- subject="Cash flow reports for all hotels"
- f = file('/app/opt/oracle/mail.txt')
- # if no mode is specified, 'r'ead mode is assumed by default
- #while True:
- # line = f.readline()
- # if len(line) == 0: # Zero length indicates EOF
- # break
- # content=line
- # print line,
-
- # Notice comma to avoid automatic newline added by Python
- content=f.read()
- f.close() # close the file
- #print content
- msg['Subject'] = subject
- msg['Reply-To'] = femail
- #msg['Cc'] = cc_string
- msg['Date'] = time.ctime(time.time())
-
- msg['X-Priority'] = '''3'''
- msg['X-MSMail-Priority'] = '''Normal'''
- print content
- dfff="du -h"
- #body=email.MIMEText.MIMEText('''"dd"+content"dd"''',_subtype='html',_charset='UTF-8')
- #msg.attach(body)
- msgText=MIMEText(content,'plain','')
- msg.attach(msgText)
-
- filename = r'/app/opt/oracle/report.zip'
- fp = open(filename,'rb')
- ctype,encoding = mimetypes.guess_type(filename)
- if ctype is None or encoding is not None:
- ctype = 'application/octet-stream'
- maintype,subtype = ctype.split('/',1)
- m = MIMEBase(maintype,subtype)
- m.set_payload(fp.read())
- fp.close()
- Encoders.encode_base64(m)
- m.add_header('Content-disposition','attachment',filename='report.zip')
- msg.attach(m)
-
- s = smtplib.SMTP('mail.e5systems.com')
- #Sing in email with password
- s.login(femail,'xxxxxxx')
- s.sendmail(femail,temail,msg.as_string())
- print 'Mailing...'
- s.close()
来自 http://blog.csdn.net/honglei915/article/details/6447401