L8包-26邮件示例

26 邮件示例

邮件简单示例

import yagmail
import os


sender ='1841000786@qq.com'     #发送人
password= 'ezdsuwnvfdjkgegj'   #申请接入授权服务密码,注意不是QQ邮箱登录密码
target = '318973407@qq.com'     #接收邮箱地址
yag = yagmail.SMTP(user=sender, password=password,host='smtp.qq.com', smtp_ssl=True)
contents = '测试test'
yag.send(to=target,subject='测试yagmail发邮件',contents=contents)
print('已发送')

#备注:跨邮箱服务商可能会有延迟,比如QQ邮箱发送到网易邮箱。谷歌邮箱服务器被封找不到

邮件内容为html,携带附件

邮件复杂示例

for i in range(0,50):		#外层for循环是发送49封邮件
    sender ='1841000786@qq.com'     #发送人
    password= 'ezdsuwnvfdjkgegj'   #申请接入授权服务密码,注意不是QQ邮箱登录密码
    target = '2765970564@qq.com'     #接收邮箱地址
    html = """
    <html lang="zh">
        <head>
            <meta charset="utf-8"
            <title>示例2</title>
        </head>
        <body>
            <h1>测试</h1>
            <p>lalallalala</p>
            <img src="http://5b0988e595225.cdn.sohucs.com/images/20181219/aec27193b3834a1694f535ba307995ad.jpeg"/>
        </body>
    </html>
    """
    attachment_path = os.path.join(os.path.dirname(__file__),'base.png')
    contents = ['测试yagmail示例2',html,attachment_path]#[邮件标题、正文、附件】
    yag = yagmail.SMTP(user=sender, password=password,host='smtp.qq.com', smtp_ssl=True)
    yag.send(to=target,contents=contents)
    print('已发送')
    time.sleep(2)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值