#!/usr/bin/env python
# -*- coding: utf-8 -*-
import smtplib,datetime,time
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.header import Header
class Email(object):
def __init__(self,email,project):
self.email=email
self.project=project
def sendEmail(self):
stmphost='127.0.0.1'
stmpport=25
smtp=smtplib.SMTP(smtphost,smtpport)
username='shuffle'
password='123'
smtp.login(username,password)
msg=MIMEMultipart('alternative')
msg['uname']=username
msg['password']=password
if len(self.email) > 1:
msg['To']=','.join(self.email)
else:
msg['To']=self.email[0]
msg['From']='shuffle@example.com'
cc=[u'ChaoSong@qq.com']
msg['Cc']=','.join(cc)
html="""
%s
""" % (self.project,)
part=MIMEText(html,'html','utf-8')
msg.attach(part)
subject='hello world!'
msg['subject']=Header(subject,'utf-8')
smtp.sendmail(msg['From'],self.email+cc,msg.as_string())
smtp.quit()
if __name__=='__main__':
try:
email=Email('ShouJianRen@qq.com',u'你好')
email.sendEmail()
except Exception,e:
print e