파이썬에서 이메일 본문의 텍스트를 굵게 만들려면 어떻게 해야 합니까? 다음 코드를 사용하여 메일을 보냅니다.
from django.core.mail import send_mail
send_mail(subject, message, sender, [email], fail_silently=False)
중요한 텍스트를 굵게 표시하고 싶습니다. 다음 코드를 사용하여 전체 문자열을 메시지로 받았습니다.
message = " Hi Customer,<br> Your OTP is <b>****</b>"
그러나 \n
로 시도하면 작동합니다 <br>
. 텍스트를 굵게 만들려면 어떻게 해야 합니까?
Django DOCS 에 따르면 html은 별도의 파일로 추가되어야 하므로 html이 있든 없든 읽을 수 있습니다(수신자가 사용하는 수신자에 따라 모든 사람이 이메일에 html을 원하는 것은 아닙니다). EmailMultiAlternatives
다음 과 같은 attach_alternative
방법 이 필요합니다 .
from django.core.mail import EmailMultiAlternatives
subject, from_email, to = 'hello', '[email protected]', '[email protected]'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다