Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface for sending HTML mail is hidden #841

Open
runxiyu opened this issue Mar 31, 2024 · 0 comments
Open

Interface for sending HTML mail is hidden #841

runxiyu opened this issue Mar 31, 2024 · 0 comments

Comments

@runxiyu
Copy link

runxiyu commented Mar 31, 2024

# 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants