zoukankan      html  css  js  c++  java
  • python 发邮件

    简单实现

    用了2个模块, smtplib 主要的三个函数login ,sendmial ,close

    SMTP.login(userpassword)

    SMTP.sendmail(from_addrto_addrsmsg[, mail_optionsrcpt_options])

    https://docs.python.org/2/library/smtplib.html#smtp-example

    #!/usr/bin/python
    #coding:utf-8
    import smtplib
    from email.mime.text import MIMEText
    user='22@qq.com' passwd='xxx'
    to='xxx@qq.com'
    
    msg=MIMEText("早上好")
    
    msg["Subject"] = 	'hi,man'
    msg['From']	=	user
    msg['to']	=	to
    print msg.as_string()
    s=smtplib.SMTP('smtp.qq.com')
    s.login(user,passwd)
    s.sendmail(user,to,msg.as_string())
    s.close()
    

      

    发中文,必须在之前加入  #coding:utf-8 ,否则会报错。


    2014-09-17 添加

    还一种发邮件的方法特别简单。

    用web.py 

    首先先安装pip install web.py

    之后简单的配置一下就可以发邮件了,妈妈再也不用担心我邮件发不了了。

    #/usr/bin/python
    import web
    web.config.smtp_server = 'smtp.qq.com'
    web.config.smtp_username = '3599xxx@qq.com'
    web.config.smtp_password = 'xxx'
    
    web.sendmail('xxx@qq.com','xxx@qq.com','subject','hi,man')
    

      web.py是一个web 框架可以写web 。

  • 相关阅读:
    Codeforces 877 C. Slava and tanks
    Codeforces 877 D. Olya and Energy Drinks
    2017 10.25 NOIP模拟赛
    2017 国庆湖南 Day1
    UVA 12113 Overlapping Squares
    学大伟业 国庆Day2
    51nod 1629 B君的圆锥
    51nod 1381 硬币游戏
    [JSOI2010]满汉全席
    学大伟业 2017 国庆 Day1
  • 原文地址:https://www.cnblogs.com/gqdw/p/3955962.html
Copyright © 2011-2022 走看看