import smtplib
from email.mime.text import MIMEText
PASSWORD = 'SWQDLJAWHFJQV'
USER = '18539043730@163.com'
FROM_ADDR = "18539043730@163.com"
TO_ADDRS = ['2698298@qq.com', '853849047@qq.com']
def send_email(subject, message, from_email, to_emails, smtp_server, smtp_port, username, password, is_use_ssl=False):
# Create a message object
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = ','.join(to_emails)
# Connect to the SMTP server
if is_use_ssl:
server = smtplib.SMTP_SSL(smtp_server, smtp_port)
else:
server = smtplib.SMTP(smtp_server, smtp_port)
# Login to the SMTP server
server.login(username, password)
# Send the email
server.sendmail(from_email, to_emails, msg.as_string())
# Disconnect from the SMTP server
server.quit()
send_email("aaa", "bb", FROM_ADDR, TO_ADDRS, 'smtp.163.com', 25, USER, PASSWORD, False)
python邮件发送
于 2023-04-11 14:43:22 首次发布