python编写发送swf邮件代码详解
python编写发送swf邮件代码详解
用python发送swf邮件,首先将swf文件上传服务器,然后将swf嵌套于html中,最后用python以html格式发送邮件即可。下面是将swf嵌套于html中的代码
Html代码
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="32" height="32">
<param name="movie" value="etime.swf">
<param name="quality" value="high">
<embed src="swf文件的绝对地址" quality="high" pluginspage = "http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100%" height="100%"></embed>
</object>
注意:在发送此类含flash的邮件时,一般都要加上外链接,并标明若不能正常显示,请点击这里。 因为并不是所有的邮件系统都能正常显示flash邮件,这还取决于邮箱自己的配置,像163的邮箱,在接受此类邮件时,会自动将标签src改为_src,以致无法正常显示
下面是python 发送邮件的一段代码:
Python代码
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import base64
Host = "XXX.XXXX.XXX" #服务器
username = "[email protected]" #邮箱
password = "XXXXXX" #密码
def sendMail(from_email, to_email ,subject,plain_text, html_body):
"""
from_email 邮件发送方
to_email 邮件接受方
subject 邮件主题
plain_text 邮件无法正常时显示
html_body 邮件正文
"""
msgRoot = MIMEMultipart(related)
msgRoot[Subject] = subject.decode(utf-8)
msgRoot[From] = from_email
msgRoot[To] = to_email.replace( ,)
msgRoot.preamble = This is a multi-part message in MIME format.
msgAlternative = MIMEMultipart(alternative)
msgRoot.attach(msgAlternative)
# 设定纯文本信息
msgText = MIMEText(plain_text.encode(utf-8),"plain","utf-8")
msgAlternative.attach(msgText)
# 设定HTML邮件正文
msgText = MIMEText(html_body, html,utf-8)
msgAlternative.attach(msgText)
#发送邮件
smtp = smtplib.SMTP(Host)
smtp.set_debuglevel(0)
# auth login 命令
smtp.docmd("HELO %s" %Host)
smtp.docmd("AUTH LOGIN")
# 发送用户名,是base64编码过的,用send发送的,所以要用getreply获取返回信息
smtp.send(base64.encodestring(username))
smtp.getreply()
# 发送密码
smtp.send(base64.encodestring(password))
smtp.getreply()
try:
相关内容
- 暂无相关文章
评论关闭