Linux 發送郵件,抄送+附件,多收件者

來源:互聯網
上載者:User

隨人Linux內建了功能強大的sendmail伺服器,但是這樣發送的郵件往往被視為垃圾郵件。以下代碼可以登入你的郵箱發送郵件,並且可以添加抄送人,添加附件,可以發給多個收件者。其中:

郵件的本文在/app/opt/oracle/mail.txt 中 ,/app/opt/oracle/report.zip是的附件。

 

DECLARE<br /> pass VARCHAR2(20) := 'Z1234';--????<br />BEGIN<br /> FOR c IN (select a.username from dba_users a,icaps_user b where 'Z'||b.username=a.username ) LOOP<br /> EXECUTE IMMEDIATE 'alter user ' || c.username || ' identified by ' || pass;<br /> END LOOP;<br />END;</p><p>#!/usr/bin/env python<br />import smtplib,mimetypes<br />from email import Encoders<br />from email.MIMEBase import MIMEBase<br />from email.MIMEText import MIMEText<br />from email.MIMEMultipart import MIMEMultipart<br />import email<br />import time</p><p>femail='xxx@xxxx.com'<br />temail =['yyyyy@yyyy.com','sssss@ssss.com']<br />ccmail=['zzzzz@zzzzz.com','ggggg@ggggg.com']</p><p>to_string =''<br />for item in temail:<br /> to_string += item +','</p><p>cc_string =''<br />for item1 in ccmail:<br /> cc_string += item1 +','</p><p>msg=MIMEMultipart()<br />msg['From'] = femail<br />msg['To'] = to_string<br />subject="Cash flow reports for all hotels"<br />f = file('/app/opt/oracle/mail.txt')<br /># if no mode is specified, 'r'ead mode is assumed by default<br />#while True:<br /># line = f.readline()<br /># if len(line) == 0: # Zero length indicates EOF<br /># break<br /># content=line<br /># print line,</p><p> # Notice comma to avoid automatic newline added by Python<br />content=f.read()<br />f.close() # close the file<br />#print content<br />msg['Subject'] = subject<br />msg['Reply-To'] = femail<br />#msg['Cc'] = cc_string<br />msg['Date'] = time.ctime(time.time())</p><p>msg['X-Priority'] = '''3'''<br />msg['X-MSMail-Priority'] = '''Normal'''<br />print content<br />dfff="du -h"<br />#body=email.MIMEText.MIMEText('''"dd"+content"dd"''',_subtype='html',_charset='UTF-8')<br />#msg.attach(body)<br />msgText=MIMEText(content,'plain','')<br />msg.attach(msgText)</p><p>filename = r'/app/opt/oracle/report.zip'<br />fp = open(filename,'rb')<br />ctype,encoding = mimetypes.guess_type(filename)<br />if ctype is None or encoding is not None:<br /> ctype = 'application/octet-stream'<br />maintype,subtype = ctype.split('/',1)<br />m = MIMEBase(maintype,subtype)<br />m.set_payload(fp.read())<br />fp.close()<br />Encoders.encode_base64(m)<br />m.add_header('Content-disposition','attachment',filename='report.zip')<br />msg.attach(m) </p><p>s = smtplib.SMTP('mail.e5systems.com')<br />#Sing in email with password<br />s.login(femail,'xxxxxxx')<br />s.sendmail(femail,temail,msg.as_string())<br />print 'Mailing...'<br />s.close()

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.