1.获取qq邮箱的授权码
https://jingyan.baidu.com/article/ac6a9a5eb439f36b653eacc0.html
2.填好自己的信息然后在个人电脑或者服务器运行如下python代码
pip install schedule
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import schedule
import time
def send_email(from_email,qq_password,to_email,subject,body):
from_email = from_email
qq_password = qq_password
smtp_server = "smtp.qq.com"
port = 587
subject = subject
body = body
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
try:
with smtplib.SMTP(smtp_server, port) as server:
server.starttls()
server.login(from_email, qq_password)
server.sendmail(from_email, [to_email], msg.as_string())
print('邮件发送成功')
except smtplib.SMTPException as e:
print(e)
print('邮件发送失败')
def send_email_at_fix_time(send_time,from_email,qq_password,to_email,subject,body):
schedule.every().day.at(send_time).do(send_email, from_email=from_email, qq_password=qq_password, to_email=to_email,
subject=subject, body=body)
while (True):
schedule.run_pending()
time.sleep(1)
def send_i_times_every_n_s(i,n,times,from_email,qq_password,to_email,subject,body):
i = i
while(i<n):
time.sleep(times)
send_email(from_email,qq_password,to_email,subject,body)
i=i+1
if __name__ == "__main__":
qq_password = "自己的授权码"
from_email = "自己的邮箱"
to_email = "收件人邮箱"
subject = "邮件标题"
body = "邮件内容"
send_time = "6:30"
send_email_at_fix_time(send_time,from_email,qq_password,to_email,subject,body)
i = 1
n=2
times = 60
send_i_times_every_n_s(i,n,times,from_email,qq_password,to_email,subject,body)