40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# @Time: 2024/5/22 11:33
|
|
|
|
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
|
|
async def email_send(receiver, subject, email_body):
|
|
|
|
# 邮件内容
|
|
msg = MIMEMultipart()
|
|
msg['From'] = 'billing-specific@kaiyuancloud.cn'
|
|
msg['To'] = receiver
|
|
msg['Subject'] = subject
|
|
msg.attach(MIMEText(email_body, 'plain'))
|
|
|
|
# SMTP 服务器设置
|
|
smtp_server = 'smtp.qiye.aliyun.com'
|
|
port = 587
|
|
username = 'billing-specific@kaiyuancloud.cn'
|
|
password = 'KYY@1234'
|
|
|
|
# 登录到 SMTP 服务器并发送邮件
|
|
try:
|
|
server = smtplib.SMTP(smtp_server, port)
|
|
server.starttls()
|
|
server.login(username, password)
|
|
server.send_message(msg)
|
|
print("Email sent successfully!")
|
|
server.quit()
|
|
return {
|
|
'status': True,
|
|
'msg': 'Email sent successfully!'
|
|
}
|
|
except Exception as e:
|
|
print("Failed to send email. Error:", str(e))
|
|
return {
|
|
'status': False,
|
|
'msg': "Failed to send email. Error: %s" % str(e)
|
|
} |