zoukankan      html  css  js  c++  java
  • 发送邮件和连接数据方法

    发送邮件 

    import yamail #上传到了pip源
    # import yagmail #发附件的附件如果是中文名,是乱码

    # yagmail
    smtp = yamail.SMTP(
    host='smtp.qq.com',#改成自己邮箱的邮箱的服务器即可
    user='511402865@qq.com',
    password='sdfsdf'#如果是163、qq等免费邮箱的话需要授权码,
    # 自己公司的邮箱,一般都使用面膜
    )

    smtp.send(to=['511402865@qq.com'],#发送给谁
    subject='你好,请查收附件',#邮件主题
    cc=['623010336@qq.com',],#抄送,如果是多个人写list
    contents='邮件正文',#邮件正文
    attachments=['笔记.txt'] #附件,如果是多个附件,写list
    )
    smtp.close()

    连接数据库

    import pymysql

    #oracle sqlserver ..

    host = '118.24.3.40'
    user = 'jxz'
    password = '123456' #字符串
    db='jxz'
    port = 3306 #int类型

    connect = pymysql.connect(host=host,user=user,
    password=password,
    port=port,db=db,
    autocommit=True
    )
    cur = connect.cursor(pymysql.cursors.DictCursor) #建立游标,仓库管理员
    pymysql.cursors.DictCursor 这行意思转成字典把
    # cur.execute('insert into students values (38,"ljl","nan",19,"天马座","北京");')
    # cur.execute('insert into students (name,class) values ("ljj2","天马座");')
    # cur.execute('delete from students where id = 21;')
    # cur.execute('update students set name="魏强2" where id=20;')

    # connect.rollback()#回滚 回滚和提交互斥的,如果提交无法回滚,没有提交之前可以回滚 sql 执行,回滚就是撤销
    # connect.commit()#提交
    cur.execute('select * from students limit 5;')
    print(cur.description) #表的描述
    # cur.execute('select * from students where id=1')

    # print('fetchmany',cur.fetchmany(2))
    # print('fetchone',cur.fetchone())
    print('fetchall',cur.fetchall())#拿到所有的结果

    # for data in cur: 也可以循环数据
    # print(data)

    cur.close() 关闭游标关闭数据库
    connect.close()
  • 相关阅读:
    北京爱丽丝幻橙科技有限公司
    红杉资本中国基金:创业者背后的创业者
    关于我们_ | 腕表时代watchtimes.com.cn
    当你想放弃的时候,问一下自己你尽力了吗
    李圣杰_百度百科
    范思哲
    DOM Traversal Example | Documentation | Qt Project
    关于QT中evaluateJavaScript()函数返回值的处理问题
    JS获取整个HTML网页代码
    javascript
  • 原文地址:https://www.cnblogs.com/weilemeizi/p/14520071.html
Copyright © 2011-2022 走看看