Office365-REST-Python-Client
Office365-REST-Python-Client copied to clipboard
Interface for sending HTML mail is hidden
# office365/outlook/mail/messages/message.py
class Message(OutlookItem):
# ...
@property
def body(self):
"""The body of the message. It can be in HTML or text format."""
return self.properties.setdefault("body", ItemBody())
@body.setter
def body(self, value):
# type: (str|ItemBody) -> None
"""Sets the body of the message. It can be in HTML or text format."""
if not isinstance(value, ItemBody):
value = ItemBody(value) # POINT OF INTEREST
self.set_property("body", value)
At the point of interest, ItemBody is initialized without any method of passing content_type, making it almost impossible to send HTML email using the Message class. While a developer could certainly resort to monkey-patching, patching a complex library with various property setters is quite challenging. It may be beneficial to expose to the developer methods of changing the body's content_type, perhaps via a separate body_content_type property that changes self.body.content_type.
Additionally, such an implementation's option to change the content_type should be exposed in office365.directory.users.user.send_mail as that's the most frequently used email-sending function, as demonstrated in the examples.