python 发送邮件

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from random import randint

def send_verification_code(receiver_email):
    verification_code = str(randint(100000, 999999))
    sender_email = 'xxxxx@gwpst.com'
    sender_password = 'E774B12D45c53ED6'
    subject = '验证码'
    message = f'您的验证码是: {verification_code}'
    # 创建邮件
    email = MIMEMultipart()
    email['From'] = sender_email
    email['To'] = receiver_email
    email['Subject'] = subject
    # 添加邮件内容
    email.attach(MIMEText(message, 'plain'))
    with smtplib.SMTP_SSL('smtp.cecloud.com', 465) as smtp:
        smtp.login(sender_email, sender_password)
        smtp.sendmail(sender_email, receiver_email, email.as_string())
# 示例调用

send_verification_code('1233@qq.com')#需要发到的邮箱
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值