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

Python httplib, detailed explanation of how to use smtplib

巴扎黑
Release: 2017-05-21 11:08:52
Original
2769 people have browsed it

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!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template