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

Improve Resend documentation and checks #293

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions django_mailbox/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,19 @@ def reply(self, message):
to retrieve that information through normal channels, so we must
pre-set it.

For conveninence, you can use django.core.mail.EmailMessage to build a Message instance::

from django.core.mail import EmailMessage

message.reply(
EmailMessage(subject="pong", body="pongpong")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to also add the to field so that the email was actually sent.

from django.core import mail

def reply_to_message(message, subject, messagebody):
    rpl = mail.EmailMessage(
        subject=subject,
        body=messagebody,
        to=[message.from_header],
    )
    message.reply(rpl)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it might be worth adding that to the reply method?

if not to:
  add to from reply_to or from_header

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting!
Is it something to document or should we expect the "reply" function to set it automatically...
WDYT @Pietro395 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Is it something to document or should we expect the "reply" function to set it automatically... WDYT @Pietro395 ?

Interesting observation @enaut
In my opinion since you are using the reply function I would expect the “to” to be set automatically if not specified.

I think that's what a user would expect

)
"""
from django.core.mail import EmailMessage as DjangoEmailMessage

if not isinstance(message, DjangoEmailMessage):
raise ValueError('Message must be an instance of django.core.mail.EmailMessage')

if not message.from_email:
if self.mailbox.from_email:
message.from_email = self.mailbox.from_email
Expand Down
29 changes: 15 additions & 14 deletions docs/topics/mailbox_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ POP3 and IMAP as well as local file-based mailboxes.

.. table:: 'Protocol' Options

============ ================ ====================================================================================================================================================================
Mailbox Type 'Protocol':// Notes
============ ================ ====================================================================================================================================================================
POP3 ``pop3://`` Can also specify SSL with ``pop3+ssl://``
IMAP ``imap://`` Can also specify SSL with ``imap+ssl://`` or STARTTLS with ``imap+tls``; additional configuration is also possible: see :ref:`pop3-and-imap-mailboxes` for details.
Gmail IMAP ``gmail+ssl://`` Uses OAuth authentication for Gmail's IMAP transport. See :ref:`gmail-oauth` for details.
Office365 API``office365://`` Uses OAuth authentication for Office365 API transport. See :ref:`office365-oauth` for details.
Maildir ``maildir://``
Mbox ``mbox://``
Babyl ``babyl://``
MH ``mh://``
MMDF ``mmdf://``
Piped Mail *empty* See :ref:`receiving-mail-from-exim4-or-postfix`
============ ================ ====================================================================================================================================================================
================ ================ ====================================================================================================================================================================
Mailbox Type 'Protocol':// Notes
================ ================ ====================================================================================================================================================================
POP3 ``pop3://`` Can also specify SSL with ``pop3+ssl://``
IMAP ``imap://`` Can also specify SSL with ``imap+ssl://`` or STARTTLS with ``imap+tls``; additional configuration is also possible: see :ref:`pop3-and-imap-mailboxes` for details.
Gmail IMAP ``gmail+ssl://`` Uses OAuth authentication for Gmail's IMAP transport. See :ref:`gmail-oauth` for details.
Office365 API ``office365://`` Uses OAuth authentication for Office365 API transport. See :ref:`office365-oauth` for details.
Maildir ``maildir://`` *empty*
Mbox ``mbox://`` *empty*
Babyl ``babyl://`` *empty*
MH ``mh://`` *empty*
MMDF ``mmdf://`` *empty*
Piped Mail *empty* See :ref:`receiving-mail-from-exim4-or-postfix`
================ ================ ====================================================================================================================================================================


.. warning::
Expand Down Expand Up @@ -117,6 +117,7 @@ Build your URI accordingly::


.. _office365-oauth:

Office 365 API
-------------------------------------

Expand Down
Loading