First, create four files: title.txt, content.txt, smtp.py, qq.txt.
In the title.txt file, put the email subject, for example:
In the content.txt file, put the email content, for example:
In the qq.txt file, put the email addresses to send to, for example:
smtp.py code#
import smtplib
from email.mime.text import MIMEText
from email.header import Header
while True:
# Email login information
email_user = 'your qq email'
email_password = 'your authorization code'
# Read recipient list
with open('qq.txt', 'r') as file:
recipient_list = file.readlines()
# Remove newline and whitespace characters at the end of each recipient email address
recipient_list = [recipient.strip() for recipient in recipient_list]
# Read email body and subject
with open('content.txt', 'r', encoding='utf-8') as file:
body_text = file.read().strip()
with open('title.txt', 'r', encoding='gbk') as file:
title_text = file.read().strip()
# Create email content
msg = MIMEText(body_text, _subtype='html', _charset='utf-8')
msg['From'] = email_user
msg['Subject'] = Header(title_text.encode('utf-8'), 'utf-8').encode()
# Connect to SMTP server
with smtplib.SMTP_SSL('smtp.qq.com', 465) as server:
server.login(email_user, email_password)
# Send email to each recipient
for recipient in recipient_list:
try:
server.sendmail(email_user, recipient, msg.as_string())
print(f'[*] Email successfully sent to {recipient}')
except smtplib.SMTPDataError as e:
if e.smtp_code == 550:
print(f'[!] Failed to send email to {recipient}: {e.smtp_error}')
elif e.smtp_code == 501:
print(f'[!] Failed to send email to {recipient}: Syntax error in recipient address')
else:
print(f'[!] Error occurred while sending email: {e}')
print('[*] All emails have been sent.')
# Display prompt message and wait for user input of yes or no to determine whether to send more emails
answer = input("Do you want to send more emails (yes/no)? ")
# If user chooses "no", exit the program; otherwise, continue sending emails
if answer.lower() == 'no':
print("Program has been closed.")
break
else:
continue
The prerequisite is to enable QQ Mail POP3, SMTP services, and obtain the service authorization code (password). It is the same for 163 Mail.
Login to QQ Mail official website: https://mail.qq.com/
After successful login/registration, go to the email homepage and click on "Settings" on the left side.
Click on "Account".
Scroll down on the account page and find the content circled in red in the image, click on "Enable".
This string of characters is the authorization code.
Fill in the authorization code and email in the code block:
email_user = 'your qq email'
email_password = 'your authorization code'
Below is a Python code to generate multiple emails:
import random
import string
def generate_random_email():
domain = 'qq.com'
username = ''.join(random.choices(string.ascii_letters + string.digits, k=8))
email = username + '@' + domain
return email
random_emails = []
for _ in range(100):
random_emails.append(generate_random_email())
for email in random_emails:
print(email)
# This code will generate 100 random QQ email addresses and print them out. Each email address has a username length of 8 characters. You can customize the username length and domain name of the email as needed.
This will generate 100 8-character QQ emails, and the generated emails will be saved in the qq.txt text file in the current directory.
Start sending emails in bulk, and if an email address does not exist, it will be skipped and the next one will be sent.