Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for python to format an email it sends?

Tags:

python

text

email

I have a script that runs at evening, it writes to a log file as it runs, and once the task completes, the text it writes is also emailed to me. Sometimes the task can fail, what I want to happen is when I get the email, the line with the error is red and bold.

So my question is, can Python format text to a certain font or color if certain conditions are met? If so, are there any good examples?

Thanks!

like image 846
MapMan Avatar asked Mar 28 '12 15:03

MapMan


People also ask

Can Python be used to send email?

Python comes with the built-in smtplib module for sending emails using the Simple Mail Transfer Protocol (SMTP). smtplib uses the RFC 821 protocol for SMTP. The examples in this tutorial will use the Gmail SMTP server to send emails, but the same principles apply to other email services.

How does Python SMTP work?

Simple Mail Transfer Protocol (SMTP) is a protocol, which handles sending e-mail and routing e-mail between mail servers. Python provides smtplib module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon.


1 Answers

I think you could just add html tags to your email and send it as HTML. However it'll change the content of your text file as it'll write additional characters to change the styling.

EXAMPLE: Sending HTML email using Python

like image 106
bobek Avatar answered Oct 15 '22 03:10

bobek