1 回答
TA贡献1744条经验 获得超4个赞
答案在 email.mime.text 模块中。该模块提供了一个函数,允许在“f”字符串中呈现 HTML 代码。必须添加这一点:
message = f"<b>Client name:</b> {client_name}<br></br> <b>Email:</b> {client_email}"
message = MIMEText(message, "html")
这是完整的代码:
from email.mime.text import MIMEText
MY_EMAIL = os.environ.get('MY_EMAIL')
MY_EMAIL_PASSWORD = os.environ.get('MY_EMAIL_PASSWORD')
message = EmailMessage()
message = f"<b>Client name:</b> {client_name}<br></br> <b>Email:</b> {client_email}"
message = MIMEText(message, "html")
message['Subject'] = "New form submitted"
message['From'] = MY_EMAIL
message['To'] = "an_email@hotmail.com"
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(MY_EMAIL, MY_EMAIL_PASSWORD)
smtp.send_message(msg_for_me)
添加回答
举报