#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import copy
import time
import sys
import urllib
import shutil
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL
#sender_qq為發(fā)件人的qq號(hào)碼
sender_qq = 'xxx'
#pwd為qq郵箱的授權(quán)碼
pwd = 'xxxuhsbehh'
#收件人郵箱receiver
receiver='xxx@xxx.com'
#郵件的正文內(nèi)容
mail_content = '測(cè)試郵件'
#郵件標(biāo)題
mail_title ='郵件標(biāo)題'
defsend_mail(sender_qq='',pwd='',\
receiver='',mail_title='',mail_content=''):
# qq郵箱smtp服務(wù)器
host_server='smtp.qq.com'
sender_qq_mail=sender_qq+'@qq.com'
#ssl登錄
smtp = SMTP_SSL(host_server)
#set_debuglevel()是用來(lái)調(diào)試的。參數(shù)值為1表示開啟調(diào)試模式,參數(shù)值為0關(guān)閉調(diào)試模式
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)
#注意MIMEText函數(shù)中的第二個(gè)參數(shù)為“plain”時(shí)侍芝,發(fā)送的是text文本。如果為“html”躏尉,則能發(fā)送網(wǎng)頁(yè)格式文本郵件。
#msg = MIMEText(mail_content, "plain", 'utf-8')
msg = MIMEText(mail_content,"plain", 'utf-8')
msg["Subject"] = Header(mail_title, 'utf-8')
msg["From"] = sender_qq_mail
msg["To"] = receiver
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()
send_mail(sender_qq=sender_qq,pwd=pwd,\
receiver=receiver,mail_title=mail_title,\
mail_content=mail_content)