通过python发送Html文件

发布于 2025-01-04 20:53:04 字数 89 浏览 2 评论 0原文

我有一个 test.html 文件,我想通过电子邮件发送(我指的是页面内容)。有没有办法从 html 中获取信息并将其作为电子邮件发送?如果您有任何其他想法请分享。

I have a test.html file that I want to send via email(I am refering about the page content). Is there a way for getting the information from the html and sending it as a email? If you have any other ideas please share.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帅哥哥的热头脑 2025-01-11 20:53:04

这是我刚刚编写的一个快速而肮脏的脚本,可能正是您正在寻找的。

https://gist.github.com/1790847

"""
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 <[email protected]>
To: Stuart Powers <[email protected]>
MIME-Version: 1.0
Content-type: text/html
Subject: %s

%s""" %(page, content)


smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.starttls()
smtpserver.login("[email protected]",os.environ["GPASS"])
smtpserver.sendmail('[email protected]', ['[email protected]'], message)

Here's a quick and dirty script I just wrote which might be what you're looking for.

https://gist.github.com/1790847

"""
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 <[email protected]>
To: Stuart Powers <[email protected]>
MIME-Version: 1.0
Content-type: text/html
Subject: %s

%s""" %(page, content)


smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.starttls()
smtpserver.login("[email protected]",os.environ["GPASS"])
smtpserver.sendmail('[email protected]', ['[email protected]'], message)
聚集的泪 2025-01-11 20:53:04

python 中读取文件的方式有很多种,python 发送电子邮件的方式也有很多。为什么不查找文档并返回一些编码错误呢?

There are many ways of reading files in python and there are also ways to send emails in python. Why don't you look up the documentation and come back with some coding error ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文