简体   繁体   English

如何在python电子邮件中更改字体

[英]How to change font in python email

I'd like to change the font size of a specific word in an email I'm sending using python. 我想更改我使用python发送的电子邮件中特定单词的字体大小。 This is the code I have so far... 这是我到目前为止的代码...

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("user@gmail.com", "password")
SUBJECT = "The subject"
TEXT = "I would like to change THIS word to bold"
message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
server.sendmail("user@gmail.com", recipients, message)
server.quit()

Is there any way I can change the word "THIS" in the text line to bold (and bigger font), but keep the other words the original font? 有什么办法可以将文本行中的“ THIS”一词更改为粗体(和更大的字体),但将其他单词保留为原始字体?

Thanks!!!! 谢谢!!!!

1. 1。

You can use this code to start bold: \\033[1m and this to end it: \\033[0m . 您可以使用以下代码以粗体开头: \\033[1m ,以结束粗体: \\033[0m

Eg str = "normal " + '\\033[1m' + "bold " + '\\033[0m' + "normal" . 例如str = "normal " + '\\033[1m' + "bold " + '\\033[0m' + "normal"

This answer may help you: print bold text in Python 此答案可能会帮助您: 在Python中打印粗体文本

2. 2。

Try this using HTML formatting. 使用HTML格式尝试操作。 It is quite simple. 这很简单。 In fact you need only the HTML tag to format words in bold. 实际上,您只需要HTML标记即可将文字设置为粗体。

However the first method works on my machine. 但是第一种方法可以在我的机器上使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM