mirror of
http://47.106.207.27:3000/Jeremy_liu/AI0814_jiaoan_public.git
synced 2026-09-27 06:14:14 +08:00
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
import smtplib
|
|
from email.mime.text import MIMEText
|
|
|
|
|
|
|
|
# Please install OpenAI SDK first: `pip3 install openai`
|
|
import os
|
|
from openai import OpenAI
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
client = OpenAI(
|
|
api_key=os.environ.get('DEEPSEEK_API_KEY'),
|
|
base_url="https://api.deepseek.com")
|
|
|
|
response = client.chat.completions.create(
|
|
model="deepseek-v4-pro",
|
|
messages=[
|
|
{"role": "user", "content": "帮我写三句幽默笑话,以国伟不要开头"},
|
|
],
|
|
stream=False,
|
|
reasoning_effort="high",
|
|
extra_body={"thinking": {"type": "enabled"}}
|
|
)
|
|
|
|
|
|
text=response.choices[0].message.content
|
|
print(text)
|
|
|
|
|
|
def send_email_qq(text,subject):
|
|
mail_host = "smtp.qq.com" # 官方指定
|
|
mail_port = 465
|
|
mail_user = "wolin105@qq.com"
|
|
mail_pass = "pingnllumhbzbceg" # 注意:不是登录密码
|
|
sender = mail_user
|
|
receivers = "1426833948@qq.com"
|
|
|
|
|
|
|
|
message = MIMEText(text, 'plain', 'utf-8')
|
|
message["From"] = sender
|
|
message["To"] = receivers
|
|
message["Subject"] = subject
|
|
|
|
try:
|
|
smtp = smtplib.SMTP_SSL(mail_host, mail_port)
|
|
smtp.login(mail_user, mail_pass)
|
|
smtp.sendmail(sender, [receivers], message.as_string())
|
|
smtp.quit()
|
|
print("邮件发送成功")
|
|
except Exception as e:
|
|
print(f"邮件发送失败: {e}")
|
|
|
|
send_email_qq(text,'笑话') |