python-emails icon indicating copy to clipboard operation
python-emails copied to clipboard

Error When Message Body Is A Zero-length String

Open r-pluss opened this issue 8 years ago • 1 comments

Please see this very short and simple gist for an example.

I believe the exception is the result of the _build_html_part method of message.py (currently starting at line 265).

As Python will evaluate a zero-length string as False in a conditional context, the subsequent calls to SafeMIMEText and set_charset are silently skipped and a None is returned.

As the RFC defines an email message body as optional, I believe a zero-length message should be allowed by this library. For my own use-case, I discovered this when setting up some automated reports to be emailed by a CI server as attachments, hence only needing a subject line and the attachments, no message body. Was very simple to workaround by adding a short message, but would like to see this be in closer compliance to the spec.

Slightly off-topic - Great job on this module, it's been extremely simple and enjoyable to work with.

r-pluss avatar Feb 22 '17 21:02 r-pluss

Hi, r-pluss! Sorry for being so late with response.

I definitely want to fail fast when email body is empty. It should protect from sending empty (i.e. broken) emails to people on mass sending.

Sending email with empty body is rare case. May be there should be parameter to allow empty body in Message constructor

lavr avatar Dec 13 '17 13:12 lavr