python发送html格式文件,通过python发送Html文件

这是一个利用Python的lxml和smtplib库快速构建并发送HTML邮件的脚本。它从命令行参数获取网页URL,解析HTML,使其链接绝对化,然后通过SMTP服务器(如Gmail)发送邮件。注意,此脚本适用于快速原型,安全性可能不强。
摘要由CSDN通过智能技术生成

这是我刚刚写的一个又快又脏的脚本,可能就是你要找的。在"""

this is a quick and dirty script to send HTML email - emphasis on dirty :)

python emailpage.py http://www.sente.cc

made to answer: http://stackoverflow.com/questions/9226719/sending-a-html-file-via-python

Stuart Powers

"""

import lxml.html

import smtplib

import sys

import os

page = sys.argv[1] #the webpage to send

root = lxml.html.parse(page).getroot()

root.make_links_absolute()

content = lxml.html.tostring(root)

message = """From: Stuart Powers

To: Stuart Powers

MIME-Version: 1.0

Content-type: text/html

Subject: %s

%s""" %(page, content)

smtpserver = smtplib.SMTP("smtp.gmail.com",587)

smtpserver.starttls()

smtpserver.login("stuart.powers@gmail.com",os.environ["GPASS"])

smtpserver.sendmail('stuart.powers@gmail.com', ['stuart.powers@gmail.com'], message)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值