python 怎么生出成一个表格,并发送邮件
2个回答
展开全部
生成excel表格可以用pyExcelerator模块
类似
from pyExcelerator import *
wb = Workbook()
ws = wb.add_sheet('Sheet1')
ws.write(0,0,'host')
ws.write(0,1,'asker')
ws.write(0,2,'head')
ws.write(0,3,'main')
ws.write(0,4,'time')
发送邮件可以用email模块,需要加附件
类似
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
import email.MIMEText
import email.MIMEBase
sender = '307212@qq.com'#发件人地址
receiver = 'zhengla@cyc.com'#收件人地址
smtpserver = 'smtp.qq.com'#邮件服务器
username = '307212178'#用户名
password = 'aaaaaa111111'#密码
smtp = smtplib.SMTP()
def send_email(msg,file_name):
msgRoot = MIMEMultipart()
msgRoot['Subject'] = 'DO not see it!!!!!'#邮件标题,这里我把标题设成了你所发的附件名
msgText = MIMEText('%s'%msg,'html','utf-8')#你所发的文字信息将以html形式呈现
msgRoot.attach(msgText)
att = MIMEText(open('%s'%file_name, 'rb').read(), 'base64', 'utf-8')#添加附件
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="%s"'%file_name
msgRoot.attach(att)
while 1:#持续尝试发送,直到发送成功
try:
smtp.sendmail(sender, receiver, msgRoot.as_string())#发送邮件
break
except:
try:
smtp.connect(smtpserver)#连接至邮件服务器
smtp.login(username, password)#登录邮件服务器
except:
print "failed to login to smtp server"#登录失败
if __name__ == "__main__":
MSG="表格"#要发送的文字
FILE="C:\\Users\1.txt"#要发送的文件
send_email(MSG,FILE)
里面的内容有删减,你可以自己添加删减
类似
from pyExcelerator import *
wb = Workbook()
ws = wb.add_sheet('Sheet1')
ws.write(0,0,'host')
ws.write(0,1,'asker')
ws.write(0,2,'head')
ws.write(0,3,'main')
ws.write(0,4,'time')
发送邮件可以用email模块,需要加附件
类似
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
import email.MIMEText
import email.MIMEBase
sender = '307212@qq.com'#发件人地址
receiver = 'zhengla@cyc.com'#收件人地址
smtpserver = 'smtp.qq.com'#邮件服务器
username = '307212178'#用户名
password = 'aaaaaa111111'#密码
smtp = smtplib.SMTP()
def send_email(msg,file_name):
msgRoot = MIMEMultipart()
msgRoot['Subject'] = 'DO not see it!!!!!'#邮件标题,这里我把标题设成了你所发的附件名
msgText = MIMEText('%s'%msg,'html','utf-8')#你所发的文字信息将以html形式呈现
msgRoot.attach(msgText)
att = MIMEText(open('%s'%file_name, 'rb').read(), 'base64', 'utf-8')#添加附件
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="%s"'%file_name
msgRoot.attach(att)
while 1:#持续尝试发送,直到发送成功
try:
smtp.sendmail(sender, receiver, msgRoot.as_string())#发送邮件
break
except:
try:
smtp.connect(smtpserver)#连接至邮件服务器
smtp.login(username, password)#登录邮件服务器
except:
print "failed to login to smtp server"#登录失败
if __name__ == "__main__":
MSG="表格"#要发送的文字
FILE="C:\\Users\1.txt"#要发送的文件
send_email(MSG,FILE)
里面的内容有删减,你可以自己添加删减
展开全部
>>> from django.core.mail import send_mail
>>> subject = 'this is a test mail'
>>> message = '<table><tr><td>123</td><td>456</td></tr></table>'
>>> send_mail(subject, message, sender_mail, [user.mail], fail_silently=False)
在message里面加有样式的html代码,然后在settings.py里面配置sender_mail的邮箱地址,登录用户以及密码,user_mail是你要发送邮件的客户邮箱。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询