Closed joshpark23 closed 6 months ago
Hi @joshpark23, I was about to ask if you were properly calling this method with an instance of EmailMessage? Did you find a solution? Do you think something would help clarify the usage of that method? Thanks
Hey @pfouque appreciate the reply -- I wasn't passing an instance of EmailMessage
to the reply
method which was causing the error
Depending on any backwards compatibility requirements, adding type hints (>= python 3.5) could be helpful.
Something less breaking could be an update to the doc string specifying the expected type of the message
param
I like typing, but I'm not sure we are ready to do that.
Maybe adding a good old parameter check would have been enough.
if not isinstance(message, EmailMessage):
raise ValueError('Message must be an instance of EmailMessage')
Could someone provide me with a working example? I fail to get it to work:
from email.message import EmailMessage
from django_mailbox.models import Message
def signal_handler(sender, message, **args):
rpl = Message( subject="pong", body="pongpong" )
message.reply(rpl)
I tried with EmailMessage
but I cannot instantiate that and over all I'm confused.
Hi @enaut,
Have you tried with Django's EmailMessage?
from django.core.mail import EmailMessage
from django_mailbox.models import Message
def signal_handler(sender, message, **args):
rpl = EmailMessage( subject="pong", body="pongpong" )
message.reply(rpl)
Thank you! Sometimes I miss the obvious! VsCode did not suggest that import, so I was not aware it might exist…
It means it wasn't obvious enough! ;) We should improve the documentation of this function
Adding this: https://github.com/coddingtonbear/django-mailbox/pull/293 Feel free to comment! I hope it will be more clear (after updating the documentation and releasing a new version)
Issue description
When calling the
reply()
method on aMessage
instance, an exception is thrown with the message "'str' object has no attribute 'from_email'".Proposed solution
Lines 658-662 in models.py, update implementation to avoid accessing the property not found on the Message model. https://github.com/coddingtonbear/django-mailbox/blob/f4a0782d3df6fb54ce474448050764cc28b64ecd/django_mailbox/models.py#L658C1-L659C1
Note
This property is found on the mailbox model but not the message, not sure why it's being accessed here. Happy to raise the PR