全部产品
云市场

网络通信

更新时间:2019-09-18 15:39:30

目录

SMTP发送邮件

  1. import smtplib
  2. from email.mime.text import MIMEText
  3. from email.header import Header
  4. # 第三方 SMTP 服务
  5. mail_host = "smtp.qq.com" # 设置服务器
  6. mail_user = "3903824xxx@qq.com" # 用户名
  7. mail_pass = "pgwhjrzdupxxxxb" # 口令,QQ邮箱是输入授权码,在qq邮箱设置 里用验证过的手机发送短信获得,不含空格
  8. sender = '390382xxx@qq.com'
  9. receivers = ['1143627xxx@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
  10. message = MIMEText('python发送邮件', 'plain', 'utf-8')
  11. message['From'] = Header("39038xxxx@qq.com", 'utf-8')
  12. message['To'] = Header("11436xxxx@qq.com", 'utf-8')
  13. subject = '使用python发送邮件的内容'
  14. message['Subject'] = Header(subject, 'utf-8')
  15. try:
  16. smtpObj = smtplib.SMTP_SSL(mail_host, 465)
  17. smtpObj.login(mail_user, mail_pass)
  18. smtpObj.sendmail(sender, receivers, message.as_string())
  19. smtpObj.quit()
  20. print("邮件发送成功")
  21. except:
  22. print("邮件发送失败")

POP3收取邮件

需要import cemail
recive(email,password,pop3_server,*,length = 1)

  • email : 邮件地址
  • password : 登录密码
  • pop3_server : 服务地址
  • length : 读取几个邮件,从时间新的开始读,默认读取最新的
  • 返回一个字典数组,每个字典代表一个邮件的内容
  1. print(myemail.recive('xxxxxxxx@qq.com','oqkgbaghkakrbiah','pop.qq.com'))
  2. >>>[{'From': ' <xxxxxxxx@qq.com>', 'To': ' <xxxxxxxx@qq.com>', 'Subject': '使用python发送邮件的内容', 'Text': 'python发送邮件'}]

HTTP - GET

  1. import requests
  2. r = requests.get("http://xxxxx?name=aaa")
  3. print(r.text)

HTTP - POST

  1. import requests
  2. postdata = { 'name':'aaa' }
  3. r = requests.post("http://xxxxx?name=aaa",data=postdata)
  4. print(r.text)