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

HTML content and bcc support #12

Open
selwin opened this issue Jun 2, 2011 · 4 comments
Open

HTML content and bcc support #12

selwin opened this issue Jun 2, 2011 · 4 comments

Comments

@selwin
Copy link

selwin commented Jun 2, 2011

Hi Chris,

I have a need for sending HTML emails with bcc and I was just wondering if you're open to accepting patches for either or both features.

My current plan is to make the send_mail command accept extra arguments (html_message and bcc).

For HTML content, this is relatively easy, I just need to tweak the send_mail command slightly to use EmailMultiAlternatives rather than the EmailMessage[1].

The bcc support would require an additional field to the Message model.

Regards,
Selwin

[1]https://docs.djangoproject.com/en/dev/topics/email/

@SmileyChris
Copy link
Owner

Hi Selwin,

I'm more than happy to accept feature patches! In fact, if you (or anyone) can prove their code quality, I'm willing to have them as direct members of the project.

There are some things which need to change with django-mailer-2. Issue #9 is the kicker - we need to be pickling the entire EmailMessage rather than the smtp text. If I recall from last time I looked, this is the stage where django-mailer [the original] has actually got to, so some code / ideas at least can be stolen from there.

Sorry, just rambling there. Back on track, you shouldn't need to alter send_mail at all. Why can't you just use the send method of EmailMessage (or subclass thereof)? Since we're using a mail backend, it should 'just work'. I'd actually be opposed to extending send_mail arguments because the idea is that django-mailer-2 should be a drop-in (and drop-out) transparent solution.

@selwin
Copy link
Author

selwin commented Jun 2, 2011

Hi Chris,

Regarding Issue #9, from a brief glance of the code I think this can be done relatively easily. We can change the send_message command to reconstruct an EmailMessage object and call its send method (or connection.send_messages(messages)) rather than directly opening an SMTP backend, we can do this since we already have all the necessary information from Message model. This will make it send using whatever email backend that the project is configured to use.

I've used the original django-mailer for a few projects but didn't like the fact that it just stores the entire pickled email object without storing any information in a more structured manner so I couldn't sort/search the log/queue by recipient etc.

How about we add a new send_html_mail function then? The reason I need an extra argument is because I'd need to pass the content in both HTML and plain text format as fallback. EmailMultiAlternatives is already a subclass of EmailMessage so it should work transparently if we fix #9.

@selwin
Copy link
Author

selwin commented Jun 3, 2011

Taking a closer look at the code, it seems like we don't have enough info to convert a Message model to an EmailMessage instance, we're missing the body part :(. I'll take a stab at converting the Message model to something like this:

class Message(models.Model):
    to_address = models.CharField(max_length=200)
    from_address = models.CharField(max_length=200)
    subject = models.CharField(max_length=255)
    message = models.TextField()
    date_created = models.DateTimeField(default=datetime.datetime.now)
    html_message = models.TextField() #Later on :)

This will give us enough info to reconstruct an EmailMessage object from a Message model.

What do you think?

@selwin
Copy link
Author

selwin commented Jun 3, 2011

Hi Chris,

I took a first stab at converting the email sending to use EmailMessage.send() on my branch. Any thoughts?

I haven't tested the code thoroughly but I did verify that it worked on non SMTP backends such as django.core.mail.backends.console.EmailBackend. I haven't cleaned up the leftover SMTP bits and pieces and currently there's one test that's failing but that's only because the test is configured to use its own custom backend, causing the email's send method to be called twice.

mjtorn pushed a commit to mjtorn/django-mailer-2 that referenced this issue Nov 17, 2014
add ru translation + whitespace cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants