pixelpassion / django-saas-boilerplate

A Django + django-rest-framework + Heroku + SaaS application boilerplate
MIT License
51 stars 10 forks source link

Improved Email handling via Saasy #36

Open jensneuhaus opened 4 years ago

jensneuhaus commented 4 years ago

☝️What is it? Why do we need it?

We should use sassy to send emails. Please prepare the logic in the following way:

📋 Todos

AntonDnepr commented 4 years ago

@jensneuhaus this part is still not cleared Have standard emails. Since we decided that we will use saasy as email backend, there is no way we can create default templates on our side, because we require saasy setup on this. Or did I get something wrong? May I ask you to clarify?

jensneuhaus commented 4 years ago

Let me try to rethink it while typing.

Goals

  1. WE want to work with saasy for sure - thats why we made it.
  2. It would still be nice, if the boilerplate could also be used by others and people could decide against sassy

How it could work

from saasy.utils import create_and_send_mail

context={
  'first_name': 'John',
  'last_name': 'Doe',
}

create_and_send_mail(
   context=context,
   subject='Test',
   to_address="john.doe@example.org"
)

create_and_send_email logic

        mail = saasy.create_mail({
            "to_address": email,
            "context": context,
            "subject": subject
          }
        )
        saasy.send_mail(mail["id"])
from saasy.utils import render_context_in_standard_template

text, html = saasy.utils.render_tontext_in_standard_template(context,subject)

# Construct an email message that uses the connection
email1 = mail.EmailMessage(
    'Hello',
    'Body goes here',
    'from@example.com',
    ['to1@example.com'],
)

# Also create HTML mail, check django-saas-email and the former code in emails how it is done

email1.send() # Send the email

Example template: https://github.com/pixelpassion/django-saas-email/blob/master/django_saas_email/templates/django_saas_email/email_base.html

Sum up

vladborisov182 commented 4 years ago

@jensneuhaus May I ask you a question? I don’t quite understand which template to use if the saasy is not connected. Can I create a simple template and paste text from context there?

jensneuhaus commented 4 years ago

Hey @vladborisov182 - sure, sorry for not having this clear enough.

The boilerplate (or saasy package, might be also the place to have this) should have one basic template we use (e.g. like this one).

Basic email template used for all emails not going through saasy

E.g.

Hello,

{text}

{EMAIL_FOOTER} <-- Would be an ENV and in settings

Fallback texts for each mail to convert context-> text

And then we also require a small alternative text for each of the emails, e.g.

Sum up

This way it first renders context -> text AND then the text into a Text/HTML email.

Not sure, if this makes no sense if we rely on saasy anyhow but its meant as a quick debug alternative.

AntonDnepr commented 4 years ago

@jensneuhaus I don't get the reasons for that. We use saasy for the emails, when we have saasy api key. When we don't have it - we rely on the developers to implement their own backend/ use existing one

I suppose IF we are going implement some emails that we're going to have in boilerplate template - we may implement fallbacks as well, but don't see much reasons to do that, because if we not using saasy, we still need to customize this part. So it still will be rewritten by devs again.

So I'd propose to first create email backend and that's it. Then if you think this should be in the template, you can assign issues on specific emails we should have in the template.

But currently, I'm confused of how this should be handled by our boileplate saasy email backend from your description. If there is default email tempalte on saasy end - it's not on our end to create it, but on saasy end.