Foundations of Python Network Programming - 读书笔记系列(3) - Email Services
Email Services这一章因为用的不多,因此大致过了一下,现在仔细看到后来会忘掉一大半。因此,到时候用到再看也不迟,这里先给个简单的例子:
import smtplib
def readManyLines():
"""Read lines from the user until they enter a line with a single
period, and return a single string."""
result = ""
while 1:
line = raw_input()
if line == '.': return result
result = result + line + "\n"
servername=raw_input("SMTP server name: ")
Fromaddress=raw_input("From address: ")
Toaddress=raw_input("To address: ")
print "Enter your message. To end, enter a line that begins with a"
print "period and has no other characters: "
MessageText=readManyLines()
server=smtplib.SMTP(servername)
server.sendmail(Fromaddress, Toaddress, MessageText)
server.quit()
def readManyLines():
"""Read lines from the user until they enter a line with a single
period, and return a single string."""
result = ""
while 1:
line = raw_input()
if line == '.': return result
result = result + line + "\n"
servername=raw_input("SMTP server name: ")
Fromaddress=raw_input("From address: ")
Toaddress=raw_input("To address: ")
print "Enter your message. To end, enter a line that begins with a"
print "period and has no other characters: "
MessageText=readManyLines()
server=smtplib.SMTP(servername)
server.sendmail(Fromaddress, Toaddress, MessageText)
server.quit()
微信扫一扫交流
作者:CoderZh
公众号:hacker-thinking (一个程序员的思考)
独立博客:http://blog.coderzh.com
博客园博客将不再更新,请关注我的「微信公众号」或「独立博客」。
作为一个程序员,思考程序的每一行代码,思考生活的每一个细节,思考人生的每一种可能。
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。