Python3实现邮件群发

(1)在 mysql 数据库创建 mail 数据库,并创建 mail 表
在这里插入图片描述

(2)将邮箱的电子邮件地址存在于mail 表中
在这里插入图片描述

(3)编写 python 程序

# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
import time
import MySQLdb

# 从数据库中获取ip地址列表
def get_addr():
    # 连接数据库
    conn = MySQLdb.Connection('127.0.0.1', 'root', '123456', 'mail')
    cursor = conn.cursor(
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现Python代码实现邮件群发工资条,你可以使用Pythonsmtplib和email库来发送邮件。下面是一个简单的示例代码: ```python import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText # 邮件服务器的配置信息 smtp_server = "smtp.example.com" smtp_port = 587 smtp_username = "your_username" smtp_password = "your_password" # 发件人和收件人信息 sender = "sender@example.com" recipients = ["recipient1@example.com", "recipient2@example.com"] # 邮件内容 subject = "工资条" body = "附件中是本月的工资条,请查收。" # 创建邮件对象 msg = MIMEMultipart() msg["From"] = sender msg["To"] = ", ".join(recipients) msg["Subject"] = subject # 添加邮件正文 msg.attach(MIMEText(body, "plain")) # 添加附件 attachment_path = "path_to_attachment.pdf" with open(attachment_path, "rb") as attachment: part = MIMEBase("application", "octet-stream") part.set_payload(attachment.read()) part.add_header("Content-Disposition", f"attachment; filename= {attachment_path}") msg.attach(part) # 发送邮件 with smtplib.SMTP(smtp_server, smtp_port) as server: server.starttls() server.login(smtp_username, smtp_password) server.send_message(msg) print("邮件发送成功!") ``` 请注意,你需要将代码中的以下信息替换为你自己的信息: - 邮件服务器的配置信息(smtp_server、smtp_port、smtp_username、smtp_password) - 发件人和收件人信息(sender、recipients) - 邮件内容(subject、body) - 附件路径(attachment_path) 这是一个简单的示例,你可以根据自己的需求进行修改和扩展。例如,你可以使用循环来发送多个工资条附件,或者从文件中读取收件人列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值