文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python gmail 多个收件人

python gmail 多个收件人

时间:2011-01-17  来源:遥望

#!send gmail with python
import smtplib,email,os,sys

from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email import Encoders
from email.header import Header 
 
fromaddr = '####@gmail.com' #where the mail from
toaddrs  = ['***@126.com','****@gmail.com','****@hotmail.com']

to_string =''
for item in toaddrs:
    to_string += item +','
subject = "test##############"
msg = MIMEMultipart()
#msg = MIMEText('body')

attachment = '附件文件名'
#msg = "\nhell"
print toaddrs

# Credentials (if needed)
username = '####'
password = 'pass'
msg["From"] = fromaddr

msg["To"] = to_string

msg["Subject"] = subject
body = "i want to send multi mail with python2222  MIME!"
msg.attach(MIMEText(body))

#attachment
fp = open(attachment,"rb")
part = MIMEBase("application", "octet-stream")
part.set_payload(fp.read())
fp.close()
Encoders.encode_base64(part)
part.add_header("Content-Disposition", "attachment; filename=%s" % attachment)
msg.attach(part)
 
# The actual mail send 
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg.as_string())
print 'success!'
server.quit()


 

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载