Chinaunix首页 | 论坛 | 博客
  • 博客访问: 100599
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 322
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-27 13:38
文章分类

全部博文(26)

文章存档

2014年(4)

2013年(22)

我的朋友

分类: Python/Ruby

2013-10-10 15:19:27

[root@os py]# cat mail_html.py 
#!/usr/bin/python
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage

mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"

f=open("log.txt")
file=f.read()
mail_body=file
msg=MIMEText("

hello world

","html","utf-8")
msg["subject"]="subject"

def sendmail():
        try:
                smtp=smtplib.SMTP()
                smtp.connect(mail_host)
                smtp.login(mail_user,mail_password)
                smtp.sendmail(mail_from,mail_to,msg.as_string())
                smtp.quit()
        except Exception ,e:
                print e

if __name__ == "__main__":
        sendmail()
[root@os py]# cat mail_fujian.py 
#!/usr/bin/python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"
body="this is test mail"

msg=MIMEMultipart(body)
mail_body=MIMEText(body)
msg["subject"]="subject"

att=MIMEText(open('/data/py/1.gif','rb').read(),'base64','gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="1.gif"'
msg.attach(att)
msg.attach(mail_body)

def sendmail():
        try:
                smtp=smtplib.SMTP()
                smtp.connect(mail_host)
                smtp.login(mail_user,mail_password)
                smtp.sendmail(mail_from,mail_to,msg.as_string())
                smtp.quit()
        except Exception ,e:
                print e

if __name__ == "__main__":
        sendmail()
[root@os py]# cat mail1.py 
#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText


mail_from="test@126.com"
mail_to="test@qq.com"
mail_host="smtp.126.com"
mail_user="test"
mail_password="test"


f=open("log.txt")
file=f.read()
mail_body=file
msg=MIMEText(mail_body)
msg["subject"]="subject"

def sendmail():
        try:
                smtp=smtplib.SMTP()
                smtp.connect(mail_host)
                smtp.login(mail_user,mail_password)
                #smtp.sendmail(mail_from,[mail_to,mail_cc,mail_cc1],msg.as_string())
                smtp.sendmail(mail_from,mail_to,msg.as_string())
                smtp.quit()
        except Exception ,e:
                print e

if __name__ == "__main__":
        sendmail()
阅读(1370) | 评论(0) | 转发(0) |
0

上一篇:svn

下一篇:Download windows 2003

给主人留下些什么吧!~~