2010-04-12
周海汉 /文
2010.4.12
同事搭了个postfix邮件服务器,用python测试了一下发邮件:
#!/usr/bin/env python
#coding:utf8
Import smtplib for the actual sending function
import smtplib
#第一封邮件
Import the email modules we’ll need
from email.mime.text import MIMEText
Open a plain text file for reading. For this example, assume that
the text file contains only ASCII characters.
textfile=’sendmail.py.html’
fp = open(textfile, ‘rb’)
Create a text/plain message
msg = MIMEText(fp.read(),’html’,’utf8’) #这是正确显示Html中文的设置,会解析html标签,不再是原始文本。
msg.set_charset(‘utf8’)#这是正确显示中文的设置
fp.close()
me = ‘ablozhou@gmail.com’# the sender’s email address
you = ‘zhouhaihan@you.cn’# the recipient’s email address
msg[‘Subject’] = ‘The contents of %s,中文标题’ % textfile
msg[‘From’] = me
msg[‘To’] = you
Send the message via our own SMTP server, but don’t include the
envelope header.
s = smtplib.SMTP(‘210.211.225.5’)
#s.login()
s.sendmail(me, [you], msg.as_string())
s.quit()
测试发送成功
更多参考:
http://docs.python.org/library/email-examples.html
如非注明转载, 均为原创. 本站遵循知识共享CC协议,转载请注明来源
FEATURED TAGS
css
vc6
http
automake
linux
make
makefile
voip
乱码
awk
flash
vista
vi
vim
javascript
pietty
putty
ssh
posix
subversion
svn
windows
删除
编译
多线程
wxwidgets
ie
ubuntu
开源
c
python
bash
备份
性能
scp
汉字
log
ruby
中文
bug
msn
nginx
php
shell
wordpress
mqueue
android
eclipse
java
mac
ios
html5
js
mysql
protobuf
apache
hadoop
install
iocp
twisted
centos
mapreduce
hbase
thrift
tutorial
hive
erlang
lucene
hdfs
sqoop
utf8
filter
草原
yarn
ganglia
恢复
scrapy
django
fsimage
flume
tail
flume-ng
mining
scala
go
kafka
gradle
cassandra
baas
spring
postgres
maven
mybatis
mongodb
https
nodejs
镜像
心理学
机器学习
Keras
theano
anaconda
docker
spark
akka-http
json
群论
区块链
加密
抽象代数
离散对数
同余
欧拉函数
扩展欧几里德算法
ES6
node-inspect
debug
win10
vscode
挖矿