Home  >  Article  >  Backend Development  >  Python httplib, detailed explanation of how to use smtplib

Python httplib, detailed explanation of how to use smtplib

巴扎黑
巴扎黑Original
2017-05-21 11:08:522662browse

Use httplib to access a certain url and then get the returned content and use smtplib to send the email script example code

Example 1: Use httplib to access a certain url and then get the returned content:

import httplib

conn
=httplib.HTTPConnection(" www.cnblogs.com")
conn.request(
"GET" , "/coderzh/archive/2008/05/13/1194445.html")
r
=conn.getresponse()
print r.read() #Get all content


Example 2: Use smtplib to send email

import smtplib
smtpServer 
= 'smtp.xxx.com'
fromaddr 
= 'foo@xxx.com'
toaddrs 
= 'your@xxx.com'
msg 
= 'Subject: xxxxxxxxx'
server 
= smtplib.SMTP(smtpServer)
server.sendmail(fromaddr, toaddrs, msg)
server.quit( )

The above is the detailed content of Python httplib, detailed explanation of how to use smtplib. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python copy objectNext article:Python copy object