python - 如何为电子邮件内容格式化我的 HTML 文本 (smtplib)
问题描述
我正在使用 SMTPlib 发送电子邮件,但我想用 HTML 格式化内容,这样看起来更好。这是我当前的代码:
msg = EmailMessage() # creating an object of EmailMessage class
msg['Subject'] = 'Day 1 of the project'
msg['From'] = Sender_Email # Defining sender email
msg['To'] = Receiver_Email # Defining receiver email
msg.set_content(f'''<pre><h3> Hi Dani,</h3>
<p style = "font-family:candara,times,helvetica; font-size:14px;">today is day <b>1</b> since you started this project.
Here is a good quote for you
<i>Fight until the end.</i>
I wish you a good day :)
Until tomorrow,
<p style = "font-family:candara,times,helvetica; font-size:14px; color:#FF0000;"><i>your fateful script</i></p></pre>''', subtype="html")
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(Sender_Email, Password) # Login to SMTP server
smtp.send_message(msg) # Sending email using send_message method by passing EmailMessage object
有没有其他的格式化方式?例如通过导入 css 文件?
解决方案
我决定使用在线 html 编辑器(例如https://htmlg.com/html-editor/)对其进行格式化,然后将其复制粘贴到我的电子邮件内容中
推荐阅读
- python - 如何写入一个空的json文件?
- python - 执行退出循环,而它应该留在循环中
- c# - 对进程终止做出反应
- javascript - BelongsToMany 急切加载为每个关联返回多个对象
- python-3.x - 如何在 Python3 的同一行上编写渐进式静态计数器?
- python - 在 tkinter 全屏上看不到 cv2 窗口
- python - Python3处理浮点错误
- embed - 尝试嵌入 video-js 直播;网站拒绝连接
- ckan - 在 CKAN 页面扩展中使用变音符号
- android - intent.resolveActivity 在 API 30 中返回 null