python登錄QQ郵箱發(fā)信的實現(xiàn)代碼
更新時間:2013年02月10日 10:22:28 作者:
python登錄QQ郵箱發(fā)信的代碼,有需要的朋友可以參考下
復制代碼 代碼如下:
# -*- coding: cp936 -*-
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib, datetime
#創(chuàng)建一個帶附件的實例
msg = MIMEMultipart()
#構造附件
att = MIMEText(open('f:\\文件名.doc', 'rb').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="文件名.doc"'
msg.attach(att)
#加郵件頭
msg['to'] = '790896688@qq.com'
msg['from'] = '12508680287@qq.com'
msg['subject'] = Header('測試 (' + str(datetime.date.today()) + ')','gb2312')
#發(fā)送郵件
server = smtplib.SMTP('smtp.qq.com')
server.login('137951467','123456')
error=server.sendmail(msg['from'], msg['to'],msg.as_string())
server.close
print error
相關文章
Python lambda和Python def區(qū)別分析
Python支持一種有趣的語法,它允許你快速定義單行的最小函數(shù)。這些叫做lambda的函數(shù),是從Lisp借用來的,可以用在任何需要函數(shù)的地方2014-11-11使用setup.py安裝python包和卸載python包的方法
這篇文章主要介紹了使用setup.py安裝python包和卸載python包的方法,大家參考使用吧2013-11-11Python實現(xiàn)WGS84火星百度及web墨卡托四種坐標系相互轉換
主流被使用的地理坐標系并不統(tǒng)一,常用的有WGS84、GCJ02(火星坐標系)、BD09(百度坐標系)以及百度地圖中保存矢量信息的web墨卡托,本文利用Python編寫相關類以實現(xiàn)4種坐標系統(tǒng)之間的互相轉換2023-08-08