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

    一,发送邮件

    python有自带的库smtplib,可以发送邮件,但是我们学习更简单的第三方库yagmail,进行发送邮件。

    首先,思考下,发送邮件需要哪些信息?可以帮助我们理解代码

     1.发送者邮箱账号,授权码密码

     2.邮箱服务器(smtp.163.com,smtp.qq.com等)

    3. 接受者邮箱账号

    4.邮件正文contents,邮件主题subject,邮件附件attachments,抄送者账号

    import yagmail
    #yagmail python第三方库,通过pip install yagmail安装
    #发送邮件的思路
    # 1.发送者邮箱,密码
    # 2.邮箱服务器(SMTP.XXX.com)
    # 3.接受者邮箱
    # 4.邮件正文,附件,抄送者
    # 5.发送
    smtpserver='smtp.qq.com'#邮箱服务器
    sender='xx@qq.com'
    password='XXX'#这里值授权码,一串字符
    reveicer='xx@163.com'
    
    m=yagmail.SMTP(host=smtpserver,user=sender,password=password,smtp_ssl=True)#连接邮箱服务器
    subject='求职简历'#邮件主题
    contents='2019年我会特别努力,期待不一样的自己。'#邮件内容
    attachments=['text.xls',r'D:programpythoncodeLYH_pythonDay6stu.xls']#附件文件
    cc=['xx1@qq.com','xx2@sina.com']
    m.send(to=['Balllyh@163.com','uitestp4p@163.com'],subject=subject,contents=contents,attachments=attachments,cc=cc)
  • 相关阅读:
    python 之字符编码
    python文件处理
    迭代器和生成器
    内置函数和匿名函数
    函数之递归
    函数 之装饰器
    python 函数进阶与闭包
    python 之 函数
    python之运算符
    python字符串内置方法
  • 原文地址:https://www.cnblogs.com/balllyh/p/10401556.html
Copyright © 2011-2022 走看看