import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def send_email(recipients, message): msg = MIMEMultipart() msg['From'] = "[email protected]" msg['To'] = ', '.join(recipients) msg['Subject'] = 'nfs监控' body = MIMEText(message, 'plain') msg.attach(body) try: with smtplib.SMTP_SSL("mail.cstnet.cn", 994) as server: server.login("[email protected]", "ZPsr?q%b@C?tm4@&") server.send_message(msg) print("邮件发送成功!") except Exception as ex: raise ex
import smtplib from email.mime.text import MIMEText from email.header import Header mail_host = "smtp.qq.com" mail_user = "[email protected]" mail_pass = "cqgrupywlmrkchcj" sender = '[email protected]' receivers = ['[email protected]'] message = MIMEText('这是邮件的内容', 'plain', 'utf-8') message['From'] = Header(f"DBEAdmin <{sender}>") message['To'] = Header(f"zxh <{','.join(receivers)}>") subject = '这是邮件的主题' message['Subject'] = Header('磁盘健康', 'utf-8') try: smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465 smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print("邮件发送成功") except smtplib.SMTPException as e: print(f"Error: 无法发送邮件 {e}") finally: smtpObj.quit()
标签:发送,import,msg,mail,message,smtplib,邮件 From: https://www.cnblogs.com/testzcy/p/18547613