PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.
https://django-graphql-auth.readthedocs.io/en/latest/
MIT License
329 stars 106 forks source link

How to use `django-templated-email`? #83

Open imsheldon opened 3 years ago

imsheldon commented 3 years ago

Hi,

I want to use django-templated-email to send emails from my app. I was looking at the documentation and found 'EMAIL_ASYNC_TASK': 'config.email.graphql_auth_async_email' this setting. I am not sure if I can use this to send email using the package django-templated-email.

from templated_email import send_templated_mail

def graphql_auth_async_email(func, args):
    """
    Task to send an e-mail for the graphql_auth package
    """

    send_templated_mail(
        template_name='welcome',
        from_email='from@example.com',
        recipient_list=['to@example.com'],
        context={
            'username':request.user.username,
            'full_name':request.user.get_full_name(),
            'signup_date':request.user.date_joined
        },
        # Optional:
        # cc=['cc@example.com'],
        # bcc=['bcc@example.com'],
        # headers={'My-Custom-Header':'Custom Value'},
        # template_prefix="my_emails/",
        # template_suffix="email",
    )

    return func(*args)
PedroBern commented 3 years ago

Hi @imsheldon you can provide your own templates following this guide.

This setting is the path of a function that will receive the email sending function and its args, so you can make it async code if you want. You do not need to send emails inside it, just call the function with the args.